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

前端 未结 18 2005
爱一瞬间的悲伤
爱一瞬间的悲伤 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 15:46

    The driver connector is not in your build path. Configure the build path and point it to the 'mysql-connector-java-5.1.25-bin.jar' (check the version which you are using). Alternatively you can use maven :D

    0 讨论(0)
  • 2020-11-22 15:49

    You will have to include driver jar for MySQL MySQL Connector Jar in your classpath.

    If you are using Eclipse: How to add dependent libraries in Eclipse

    If you are using command line include the path to the driver jar using the -cp parameter of java.

    java -cp C:\lib\* Main
    
    0 讨论(0)
  • 2020-11-22 15:54

    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

    0 讨论(0)
  • 2020-11-22 15:54

    It is because the WEB-INF folder does not exist at the location in the sub directory in the error. You either compile the application to use the WEB-INF folder under public_html OR copy the WEB-INF folder in sub folder as in the error above.

    0 讨论(0)
  • 2020-11-22 15:58

    For Gradle-based projects you need a dependency on MySQL Java Connector:

    dependencies {
        compile 'mysql:mysql-connector-java:6.0.+'
    }
    
    0 讨论(0)
  • 2020-11-22 15:58

    In the project into the folder Libraries-->right click --> Add Library --> Mysqlconnector 5.1

    0 讨论(0)
提交回复
热议问题