ClassNotFoundException com.mysql.jdbc.Driver [英] ClassNotFoundException com.mysql.jdbc.Driver
问题描述
这个问题可能在这里问了很多次。在做了一些谷歌搜索上面的错误并做了一些更新后,我无法理解为什么我仍然会收到该错误。我已经把我的驱动程序 - mysql-connector-java-5.1.5-bin放在类路径中了:
This question might have asked here number of times . After doing some google search for the above error and doing some update, I can't understand why I'm still getting that error. I've already put my driver-- mysql-connector-java-5.1.5-bin in the classpath:
Java_Home\jre\lib\
Java_Home\jre\lib\ext\
Java_Home\lib
我用来连接mysql数据库的代码是:
and the code which I'm using to connect to mysql database is:
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/mail","root","");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("select message_body from deadletter");
String dbtime;
while (rs.next()) {
dbtime = rs.getString(1);
System.out.println(dbtime);
}
con.close();
}
catch (SQLException e) {
System.out.println("Connection Failed! Check output console");
e.printStackTrace();
}
}
以及上面的完整堆栈跟踪例外是:
and the complete stacktrace of the above exception is:
java.lang.ClassNotFoundException: com.mysql.jdbc:Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:307)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at mail.main(mail.java:114)
<现在,我在这里做错了什么?
Now, what's wrong I'm doing here?
推荐答案
最常见的原因是您的类加载位置存在冲突。例如,如果你有2个位置,一个有JDBC驱动程序而另一个没有,那么如果你的类加载器从第一个位置加载,而第一个位置的某个类想要使用驱动程序 - 驱动程序不在那里。因此,寻找使用您的驱动程序的重复JAR
The most common cause is that you have some conflict in where your classes are loaded from. For example if you have 2 locations and one has JDBC drivers and the other one not then if your classloader loads from the 1st location and some class from the 1st location wants to use the driver - the driver is not there. So look for the duplicate JARs that are using your driver
这篇关于ClassNotFoundException com.mysql.jdbc.Driver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!