ClassNotFoundException: com.mysql.jdbc.Driver [duplicate]

浪尽此生 提交于 2019-11-29 12:43:10

The zip you downloaded should contain a file named mysql-connector-java-5.0.8-bin.jar or similar. Version might be different. Check that it is present and check that it is directly in your classpath (not in a subdirectory etc.).

If that's alright, check that your classpath variable is not overwritten by something else. If you execute your program manually do it like this: java -cp "C:\Program Files\Java\jre6\lib\ext\mysql-connector-java-5.0.8-bin.jar:." YourClass

If you are using an IDE such as eclipse, check your build-path settings there. (In eclipse you would right click your project -> Properties -> Java Build Path -> Add external JARs and then supply the path of your connector...jar.

I think the problem is you are putting mysql-connector-java-5.1.18-bin file rather you have to put "mysql-connector-java-5.0.5.jar" file there.

i have made a web application in eclipse(IDE). so if you are making a web application on eclipse(IDE) then you can put "mysql-connector-java-5.0.5.jar" in the lib folder. below is the path where i put my "mysql-connector-java-5.0.5.jar" file...

C:\Users\Abhishek\workspace\MyProject\WebContent\WEB-INF\lib\mysql-connector-java-5.0.5.jar

The CLASSPATH variable can't be just the directory, it has to have the actual jar name.

a bat file would look like

@echo off
set CLASSPATH=program.jar;mysql-connector-java-5.1.18-bin.jar

:start

start javaw.exe MainClass

program.jar (would contain the MainClass class as the main class) and the mysql.jar would have to reside in the same directory.

For Eclipse you have to set your project Build Path to include the mysql...jar.

I encountered the same problem and what I did to solve it:

  1. Downloaded the .jar accordingly to the server used: For mySQL I downloaded mysql-connector-java-5.1.18-bin.jar

  2. Added CLASSPATH in SYSTEM VARIABLES with the whole name of the .jar used. If you already have CLASSPATH var then add in it, as in PATH ";Path to Jar/jar file name" something like: CLASSPATH = d:\requisites\mySQL_connector\mysql-connector-java-5.1.18-bin.jar

  3. In Eclipse project: Right click on project->Build Path-.Configure build path. Add external JARs and add the jar file. When you succesfully do this step it will appear on the project in "Reference Libraries"

  4. An important step(if you use Android Development Tools framework as I am using) is to add also that JAR file in libs folder of your app. I did this by copy-paste the jar from my path(d:\requisites\mySQL_connector) to libs folder of my project.

Restarted the project and it worked on second run.

SHIVARAJU P S

Try this

If you create the Dynamic Java Project(In Eclipse)

  1. Check the your build path for respective project

    • Step 1. Right click on your Project and Select Properties

    • Step 2. On the right side you will get the Deployment Assembly

    • Step 3. Click On the add and select Archives from File system

    • Step 4. Click on the again add and select the your respective database jar files.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!