java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4233049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
提问by SLA
I am getting this error when compiling my java program
编译我的java程序时出现这个错误
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Then I knew that I should add the path of mysql-connector-java-3.1.14-bin.jar
to the java classpath. I am using Windows XP, I edited the classpath in the controlpanel/system/enviromental variables
然后我知道我应该将 的路径添加mysql-connector-java-3.1.14-bin.jar
到java类路径。我使用的是 Windows XP,我在控制面板/系统/环境变量中编辑了类路径
the classpath was : .;C:\j2sdk1.4.2_16\jre\lib;
类路径是: .;C:\j2sdk1.4.2_16\jre\lib;
so now it became : .;C:\j2sdk1.4.2_16\jre\lib;C:\Program Files\mysql-connector-java-3.1.144
所以现在变成了: .;C:\j2sdk1.4.2_16\jre\lib;C:\Program Files\mysql-connector-java-3.1.144
however, i still get the same error, moreover, when I type set classpath in the cmd ( just to check what is the current classpath ) i get :
但是,我仍然遇到相同的错误,此外,当我在 cmd 中键入 set classpath 时(只是为了检查当前的类路径是什么),我得到:
CLASSPATH= .;C:\j2sdk1.4.2_16\jre\lib;
can anyone help me fix this ?
谁能帮我解决这个问题?
采纳答案by thejh
You have to put the full path to the jarfile in the classpath (including the filename):
您必须将 jarfile 的完整路径放在类路径中(包括文件名):
.;C:\j2sdk1.4.2_16\jre\lib;
C:\Program Files\mysql-connector-java-3.1.144\mysql-connector-java-3.1.14-bin.jar
As Hippo said, you have to restart cmd
after changing that. If it doesn't work, launch your program like this:
正如河马所说,您必须cmd
在更改后重新启动。如果它不起作用,请像这样启动您的程序:
java -cp ".;C:\j2sdk1.4.2_16\jre\lib;
C:\Program Files\mysql-connector-java-3.1.144\mysql-connector-java-3.1.14-bin.jar"
my.class.Name
回答by Jay Patel
- Open Netbeans IDE
- Right-click your Project.
- Select Properties.
- On the left-hand side click Libraries.
- Under "Compile" tab - click Add Jar/Folder button.
- Select Downloaded "mysql-connector-java-5.1.25-bin.jar" file (Download Connector/Jfrom dev.mysql.com)
- Click OK
- Run Again... Its work.
- 打开 Netbeans IDE
- 右键单击您的项目。
- 选择属性。
- 在左侧单击库。
- 在“编译”选项卡下 - 单击添加 Jar/文件夹按钮。
- 选择下载的“mysql-connector-java-5.1.25-bin.jar”文件(从dev.mysql.com下载Connector/J)
- 单击确定
- 再次运行...它的工作。
Thanks...
谢谢...
回答by HN Singh
You just need to copy the mysql-connector-java-5.1.39-bin file in the Libraries of the project folder. Everything will work fine.
你只需要复制项目文件夹Libraries中的mysql-connector-java-5.1.39-bin文件即可。一切都会好起来的。