[英]Eclipse: I have added the JAR file. java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
I am using Eclipse, I have added the JAR file under lib->mysql-connector...jar
, but I am still getting the error that the class is not found. 我正在使用Eclipse,已在
lib->mysql-connector...jar
下添加了JAR文件,但仍收到未找到该类的错误。
I have read many other posts related to the same problem, and they point to adding the JAR file, but I have already done this step. 我已经阅读了许多与同一问题相关的其他文章,它们指向添加JAR文件,但是我已经完成了这一步。
Thanks for the help. 谢谢您的帮助。
Error: 错误:
Exception in thread "main" java.lang.ClassNotFoundException: com.mysql.jbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:171)
at TTDB.TT_DoQuery(TTDB.java:65)
at TTDB.TT_Insert(TTDB.java:58)
at TTDB.main(TTDB.java:109)
Code: 码:
try{
Class.forName("com.mysql.jbc.Driver");
// Connect to the database
connect = DriverManager.getConnection(address);
statement = connect.createStatement();
resultSet = statement.executeQuery(query);
}
catch (Exception e){
throw e;
} finally {
TT_Close();
}
**Screenshots* **截图*
You're missing a d
. 您缺少
d
。
Class.forName("com.mysql.jdbc.Driver");
Note that JDBC 4 compliant Driver
implementations don't need to be explicitly loaded with Class.forName(String)
. 请注意,不需要使用
Class.forName(String)
显式加载兼容JDBC 4的Driver
实现。 The Driver
is registered through classpath scanning. 通过类路径扫描注册
Driver
。 Find out if your library is JDBC 4 compliant and remove the call to Class.forName(String)
if it is. 找出您的库是否兼容JDBC 4,并删除对
Class.forName(String)
的调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.