我收到了这个错误
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
但我的pom.xml
及其maven dependencies
文件夹中有此课程。每次我添加一些lib到pom.xml
一切都还可以,直到现在我甚至尝试做maven - >更新项目,但没有帮助
我正在使用Eclipse Juno
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection c = DriverManager.getConnection("jdbc:mysql://localhost/test", "root", "*****");
return c;
编辑
pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
<scope>compile</scope>
</dependency>
答案 0 :(得分:0)
有一种更直接的方式来建立联系:
连接c = new com.mysql.jdbc.Driver()。connect(“jdbc:mysql:// localhost / test?user = root&amp; password = root”,null);
没有类似ClassNotFoundException的谜题
答案 1 :(得分:0)
如何启动服务器?你是如何部署的?从日食里面?如果jar在那里,请检查已部署的文件夹。如果您正在使用eclipse,它将在:
${workspace}\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\ROOT\WEB-INF\lib
(如果使用Windows)
您的maven配置和代码看起来很好,我会说这是部署问题。
答案 2 :(得分:-2)
你需要将mysql连接器jar添加到项目类路径中作为外部jar .. 然后它会正常工作:D