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

前端 未结 18 2026
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  • 2020-11-22 16:05

    If you are using tomcat then along with project directory you should also copy the database connector jar file to tomcat/lib. this worked for me

    0 讨论(0)
  • 2020-11-22 16:07

    This needs to be used as of 2020

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.18</version>
        </dependency>
    
    0 讨论(0)
  • 2020-11-22 16:10

    Every one has written an answer but I am still surprised that nobody actually answered it by using the best simple way.
    The people answer that include the jar file. But, the error will still occur.

    The reason for that is, the jar is not deployed when the project is run. So, what we need to do is, tell the IDE to deploy this jar also.

    The people here has answered so many times that put that jar file in the lib folder of WEB-INF. That seems okay, but why do it manually. There is simple way. Check the below steps:

    Step 1: If you haven't referenced the jar file into the project then, reference it like this.

    Right click on the project and go to the project properties. Then, go to the java build path, then add external jar file via that.

    But this will still not solve the problem because adding the external jar via build path only helps in compiling the classes, and the jar will not be deployed when you run the project. For that follow this step

    Right click on the project and go to the project properties. Then, go to the Deployment Assembly then press Add , then go to the java build path entries and add your libraries whether it is jstl, mysql or any other jar file. add them to deployment. Below are the two pictures which display it.

    0 讨论(0)
  • 2020-11-22 16:10

    check for jar(mysql-connector-java-bin) in your classpath download from here

    0 讨论(0)
  • 2020-11-22 16:10

    I'm developing a simple JavaFX11 application with SQLite Database in Eclipse IDE. To generate report I added Jasper jars. Suddenly it throws "THIS" error.

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

    It was running good (BEFORE THIS ADDITION). But suddenly!

    I'm not using maven or other managers for this simple application. I'm adding jars manually.

    I created "User Library" and added my jars from external folders.

    PROBLEM OCCURING AREA: My "User Library" are marked as system library. I just removed the marking. Now its not a system library. "NOW MY PROJECT WORKING GOOD".

    DEBUG MYSELF: Tried other things: AT RUN CONFIGURATION: Try, removing library and add jars one-by-one and see. - here you have to delete all jars one by one, there is no select all and remove in eclipse right now in run configuration. So the error messages changes form one jars to another.

    Hope this helps someone.

    0 讨论(0)
  • 2020-11-22 16:13

    The exception can also occur because of the class path not being defined.

    After hours of research and literally going through hundreds of pages, the problem was that the class path of the library was not defined.

    Set the class path as follows in your windows machine

    set classpath=path\to\your\jdbc\jar\file;.
    
    0 讨论(0)
提交回复
热议问题