ClassNotFoundException com.mysql.jdbc.Driver [英] ClassNotFoundException com.mysql.jdbc.Driver

查看:28
本文介绍了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_Homejrelib
Java_Homejrelibext
Java_Homelib

我用来连接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屋!

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