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.
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.
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
.
Class.forName("com.mysql.jdbc.Driver");
Note that JDBC 4 compliant Driver
implementations don't need to be explicitly loaded with Class.forName(String)
. The Driver
is registered through classpath scanning. Find out if your library is JDBC 4 compliant and remove the call to Class.forName(String)
if it is.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.