我用mysql建的数据库怎么在myeclipse里面用?那个mysql-connector-java-5.1.6-bin应该放在哪儿?
2013-11-19
展开全部
eclipse中链接mysql数据库
例证分析:
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Success loading Mysql Driver!");
}catch(Exception e){
System.out.println("Error loading Mysql Driver!");
e.printStackTrace();
}
try{
Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/数据库名","用户名","密码");
System.out.println("Success connect Mysql server!");
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery("select * from 表名");
//查询操作显示数据表中第1、2、4列数值
while(rs.next()){
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(4));
}
}catch(Exception e){
System.out.println("get data error!");
e.printStackTrace();
}
mysql-connector-java-5.1.6-bin放在Refenced Liberaries下,操作方法如下:
选中所建的项目——右击选“Build Path”——“Add External Archives...“——mysql-connector-java-5.1.6-bin
例证分析:
try{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Success loading Mysql Driver!");
}catch(Exception e){
System.out.println("Error loading Mysql Driver!");
e.printStackTrace();
}
try{
Connection connect = DriverManager.getConnection("jdbc:mysql://localhost:3306/数据库名","用户名","密码");
System.out.println("Success connect Mysql server!");
Statement stmt = connect.createStatement();
ResultSet rs = stmt.executeQuery("select * from 表名");
//查询操作显示数据表中第1、2、4列数值
while(rs.next()){
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
System.out.println(rs.getString(4));
}
}catch(Exception e){
System.out.println("get data error!");
e.printStackTrace();
}
mysql-connector-java-5.1.6-bin放在Refenced Liberaries下,操作方法如下:
选中所建的项目——右击选“Build Path”——“Add External Archives...“——mysql-connector-java-5.1.6-bin
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询