今天在用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(); }
*/
}