Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

JDBC&Mysql : ClassNotFoundException: com.mysql.jdbc.Driver

843854May 7 2005 — edited Feb 17 2007
i'm a newbie to jdbc and was trying out a basic program to connect to the database. i'm gettin the same
error msg as a few others were but still cant figure out whats wrong. my output to the program pasted below was:

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Jdbc11.main(Jdbc11.java:12)

The program code i used was:

import java.sql.*;
import java.sql.DriverManager;


public class Jdbc11 {
public static void main(String args[]){
System.out.println(
"Copyright 2005, MK");
try {
Statement stmt;

Class.forName("com.mysql.jdbc.Driver"); //registering jdbc driver

//classes

String url =
"jdbc:mysql://localhost:3306/mysql";
Connection con = DriverManager.getConnection(url,"root", "");

System.out.println("URL: " + url);
System.out.println("Connection: " + con);

stmt = con.createStatement();

stmt.executeUpdate(
"CREATE DATABASE JunkDB");
stmt.executeUpdate(
"GRANT SELECT,INSERT,UPDATE,DELETE," +
"CREATE,DROP " +
"ON JunkDB.* TO 'auser'@'localhost' " +
"IDENTIFIED BY 'drowssap';");

con.close();
} //end try
catch( Exception e ) {
e.printStackTrace();
}//end catch

}//end main
}//end class Jdbc11

i've included the sqldriver jar file (mysql-connector-java-3.1.8-bin.jar) in C:\j2sdk1.4.2_08\jre\ext . isn't that sufficient? is there a difference in the commands to run this program or?
please help! :/
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 17 2007
Added on May 7 2005
40 comments
1,838 views