java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse
It seems the mysql connectivity library is not included in the project. Solve the problem following one of the proposed solutions:
- MAVEN PROJECTS SOLUTION
Add the mysql-connector dependency to the pom.xml project file:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.39</version>
</dependency>
Here you are all the versions: https://mvnrepository.com/artifact/mysql/mysql-connector-java
- ALL PROJECTS SOLUTION
Add the jar library manually to the project.
Right Click the project -- > build path -- > configure build path
In Libraries Tab
press Add External Jar
and Select
your jar.
You can find zip for mysql-connector here
- Explanation:
When building the project, java throws you an exception because a file (the com.mysql.jdbc.Driver class) from the mysql connectivity library is not found. The solution is adding the library to the project, and java will find the com.mysql.jdbc.Driver
If you got the error in your IDE(compile-time error), you need to add your mysql-connector jar file to your libs and add this to your referenced library of project too.
If you get this error when you are running it, then probably its because you have not included mysql-connector JAR file to your webserver's lib folder.
Add mysql-connector-java-5.1.25-bin.jar
to your classpath and also to your webserver's lib directory. Tomcat lib path is given as an example Tomcat 6.0\lib