java中myeclipse连接mysql问题(java.lang.ClassNotFoundException: com.mysql.jdbc.Driver)
1、往项目中添加mysql-connector-java-5.0.8-bin.jar。驱动jar包;(右击项目buildpath——》add)
2、 String driver = "com.mysql.jdbc.Driver";
// URL指向要访问的数据库名
String url = "jdbc:mysql://127.0.0.1:3306/sxu_art_group";
String user = "root";
String password = "";
Class.forName(driver);
try {
// 加载驱动程序
Class.forName(driver);
// 连续数据库
Connection conn = DriverManager.getConnection(url, user, password);
if(!conn.isClosed()){
System.out.println("Succeeded connecting to the Database!");
}
// statement用来执行SQL语句
Statement statement = conn.createStatement();
// 要执行的SQL语句
String sql = "select * from student";
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
相关文章
- 02-17ambari-server启动出现ERROR main] DBAccessorImpl:106 - Error while creating database accessor java.lang.ClassNotFoundException:com.mysql.jdbc.Driver问题解决办法(图文详解)
- 02-17IntelliJ IDEA web项目进行数据库连接时出现java.lang.ClassNotFoundException: com.mysql.jdbc.Driver错误解决办法
- 02-17java中myeclipse连接mysql问题(java.lang.ClassNotFoundException: com.mysql.jdbc.Driver)
- 02-17eclipse,myeclipse中java连接数据库的问题
- 02-17解决java.lang.ClassNotFoundException: com.mysql.jdbc.Driver问题(真实有效)