idea-maven提示错误:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

今天在用maven工程连接数据库的时候报了这样一个错误。

条件:已在pom文件中添加mysql-connector-java-5.1.39.jar依赖依然无法解决

最后的解决方法:去掉依赖,自己去官网下载了mysql-connector-java-5.1.45-bin.jar包。

File-project structure-library-点+号,添加自己下载的jar包,竟然就不报错了。

部分代码:

try{

Class.forName("com.mysql.jdbc.Driver");

}catch(ClassNotFoundException e) {

System.out.println("Where is your mysql JDBC Driver? "

+"Include in your library path!");

e.printStackTrace();

logger.info("Where is your mysql JDBC Driver? "

+"Include in your library path!");

logger.info(USE.getTrace(e));

continue;

}

System.out.println("mysql JDBC Driver Registered!");

logger.info("mysql JDBC Driver Registered!");

Connection connection =null;

try{

connection = DriverManager.getConnection(

"jdbc:mysql://localhost:3306/Mytest?autoReconnect=true&useSSL=false",

"root","aa223183");

}catch(SQLException e) {

System.out.println("Connection Failed! Check output console");

e.printStackTrace();

logger.info("Connection Failed! Check output console");

logger.info(USE.getTrace(e));

continue;

/*

* try { Thread.sleep(1000*10); } catch (InterruptedException

* e1) { //TODO Auto-generated catch block* e1.printStackTrace(); }

*/

}

你可能感兴趣的:(idea-maven提示错误:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver)