I have this Exception but the Jar file are in the referenced libraries.
不知道问题出在哪里。代码没问题,我已将所有内容添加到构建路径中。 String DRIVER_CLASS_NAME = "com.mysql.jdbc.Driver";
final String DBMS = "jdbc:mysql";
final String SERVER="localhost";
final String DATABASE = "mapDB";
final int PORT=3306;
final String USER_ID = "MapUser";
final String PASSWORD = "map";
Connection conn;//gestisce una connessione
private void initConnection() throws DatabaseConnectionException {
try {
Class.forName(DRIVER_CLASS_NAME);/
}catch(ClassNotFoundException e) {
e.printStackTrace();
}
try {
conn=(Connection)DriverManager.getConnection(DBMS + "://" + SERVER + ":" + PORT + "/" + DATABASE,USER_ID,PASSWORD);
}catch(SQLException ex) {
throw new DatabaseConnectionException();
}
}
最佳答案
您的image显示您的类路径上有 mysql-connector-java-5.1.7-bin.jar
。
在 Maven Repository 中查找该文件时,有很多 5.1.x
版本,但没有 5.1.7
。
5.1.7
似乎存在缺陷,已被撤回。
尝试使用另一个5.1.x
版本,例如the latest ,当前为 5.1.46
。
关于java - ClassNotFoundException : com. mysql.jdbc.Driver 但它位于类路径中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50632633/