java.lang.ClassNotFoundException:com.mysql.jdbc.Driver [英] java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

查看:151
本文介绍了java.lang.ClassNotFoundException:com.mysql.jdbc.Driver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编译java程序时出现此错误

I am getting this error when compiling my java program

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

然后我知道我应该添加 mysql-connector-java的路径-3.1.14-bin.jar 到java类路径。我使用的是Windows XP,我在controlpanel / system / enviromental变量中编辑了类路径

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

类路径为:。; C:\ j2sdk1 .4.2_16\jre\lib;

现在变为:。; C:\ j2sdk1 .4.2_16\jre\lib; C:\Program Files \mysql-connector-java-3.1.144

但是,我仍然得到相同的错误,此外,当我在cmd中键入set classpath(只是为了检查当前的类路径)我得到:

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 :

CLASSPATH= .;C:\j2sdk1.4.2_16\jre\lib;

任何人都可以帮我解决这个问题吗?

can anyone help me fix this ?

推荐答案

你必须在类路径中包含jar文件的完整路径(包括文件名):

You have to put the full path to the jarfile in the classpath (including the filename):

.;C:\j2sdk1.4.2_16\jre\lib;
C:\Program Files\mysql-connector-java-3.1.144\mysql-connector-java-3.1.14-bin.jar

正如Hippo所说,更改后必须重新启动 cmd 。如果它不起作用,启动你的程序如下:

As Hippo said, you have to restart cmd after changing that. If it doesn't work, launch your program like this:

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

这篇关于java.lang.ClassNotFoundException:com.mysql.jdbc.Driver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆