java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse

前端 未结 18 2154
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 15:41

What is wrong with the code there are lots of error while debugging. I am writing a code for a singleton class to connect with the database mysql.

Here is my code

18条回答
  •  萌比男神i
    2020-11-22 16:04

    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:

    
        mysql
        mysql-connector-java
        5.1.39
    
    

    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

提交回复
热议问题