Reputation: 35
I have this Exception but the Jar file are in the referenced libraries.
I dont't know where is the problem. The code is alright and I have added all in the build path. 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();
}
}
Upvotes: 0
Views: 996
Reputation: 159096
Your image shows you have mysql-connector-java-5.1.7-bin.jar
on your classpath.
When looking for that file in the Maven Repository, there are many 5.1.x
versions, but not 5.1.7
.
It would seem that 5.1.7
is flawed and have been retracted.
Try using another 5.1.x
version, e.g. the latest, which currently is 5.1.46
.
Upvotes: 1
Reputation: 108
Have you tried removing mysql-connector-java-5.1.7-bin.jar, just keep mysql-connector-java-8.0.11.jar
Upvotes: 0
Reputation: 125
It appears that there are different versions of MySQL JDBC connectors, as the second print shows.
Maybe the existence of 2 references to the same lib is causing the ClassNotFoundException, or your project's build is not up to date.
I suggest you to keep only one version of the connector on the references of your project, clear and build the project again.
Upvotes: 0