[英]Class not found com.mysql.jdbc.Driver
I got this error 我得到这个错误
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
but I have this class in my pom.xml
and its in my maven dependencies
folder. 但是我的pom.xml
有这个类,而我的maven dependencies
文件夹中有这个类。 Each time I added some lib to pom.xml
everything was ok till now I even try to do maven -> update project but it didn't help 每次我向pom.xml
添加一些lib到现在为止一切正常,我什至尝试执行maven->更新项目,但这无济于事
Im using Eclipse Juno 我正在使用Eclipse Juno
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection c = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "*****");
return c;
Edit pom.xml
编辑pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
<scope>compile</scope>
</dependency>
There is a more straitforward way to get a connection: 有一种更严格的方法来建立连接:
Connection c = new com.mysql.jdbc.Driver().connect("jdbc:mysql://localhost/test?user=root&password=root", null); 连接c =新的com.mysql.jdbc.Driver()。connect(“ jdbc:mysql:// localhost / test?user = root&password = root”,null);
There will be no puzzles like ClassNotFoundException 不会有像ClassNotFoundException这样的难题
How do you start the server? 您如何启动服务器? How do you do deployment? 您如何部署? From inside eclipse? 从月食内部? Check the deployed folder if the jar is there. 检查jar所在的部署文件夹。 If you're using eclipse it will be in: 如果您使用的是eclipse,它将位于:
${workspace}\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\ROOT\\WEB-INF\\lib
(if using windows) ${workspace}\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\ROOT\\WEB-INF\\lib
(如果使用Windows)
Your maven config and code look fine, I would say it's a deployment problem. 您的Maven配置和代码看起来不错,我想这是一个部署问题。
您需要将mysql连接器jar添加到项目类路径中作为外部jar ..然后它将正常工作:D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.