Chinaunix首页 | 论坛 | 博客
  • 博客访问: 356215
  • 博文数量: 102
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 1116
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-29 16:21
文章分类

全部博文(102)

文章存档

2014年(10)

2011年(1)

2008年(2)

2007年(89)

我的朋友

分类: Java

2007-04-09 21:46:16

首先系统必须具有com.jdbc.mysql.Driver,也就是mysql的驱动。从 或者
http://dev.mysql.com/downloads/connector/j/5.0.html 下载完后,将其中的jar包拷贝到jdk目录下的/jre/lib/ext/下,或者在classpath中添加该包的路径。
如:
public static void main(String argv[])
 {
  String url="jdbc:mysql://218.192.175.84:3306/dcampusfw?user=root&password=test";
  try
  {
  Class.forName("com.mysql.jdbc.Driver");
  Connection conn=DriverManager.getConnection(url);
  PreparedStatement pm=conn.prepareStatement("select * from test");
  ResultSet rs=pm.executeQuery();
  pm.close();
  conn.close();
  rs.close();
  System.out.println("OK!");
  }
  catch (Exception ex) {
   System.out.println (ex.getLocalizedMessage());
  }
 }
 
 
阅读(975) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~