Class Not Found Exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver? [duplicate]

非 Y 不嫁゛ 提交于 2019-12-13 09:14:11

问题


Possible Duplicate:
com.mysql.jdbc.Driver not found with mysql connector in buildpath

I'm working on connecting MySQL database to a Java program. When I run my program I am getting this error

Class Not Found Exception: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

for this line

try{ Class.forName("com.mysql.jdbc.Driver").newInstance();

So, what's the problem? I'm placing the connector in the project's file.. Is the correct or should it be in another location?

OS Windows XP, Eclipse 4.0, mysql connector 5.1.22


回答1:


JAR file need to add to project class path.

First Right click on you Eclipse Project,  Project --> Build Path --> Configure Build Path. Under Libraries tab, click Add Jars or "Add External JARs".



回答2:


You don't even need that line of code, any time in the last five years or so. Just delete it,




回答3:


The jar file should be in your classpath. If you have created the project through an IDE, make sure you add the jar in your build path.




回答4:


You have to include the connector jar file in your project's build path. In eclipse project properties dialog, go to "Java Build Path" and add the jar file in "Libraries" tab




回答5:


the jar should be included in your classpath. In your IDE, configure your build path and add the required jar in your libraries section.



来源:https://stackoverflow.com/questions/14098404/class-not-found-exception-java-lang-classnotfoundexception-com-mysql-jdbc-driv

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