aspose file tools*
The moose likes JDBC and the fly likes java.lang.ClassNotFoundException: com.mysql.jdbc.Driver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" Watch "java.lang.ClassNotFoundException: com.mysql.jdbc.Driver" New topic
Author

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

kalai arasan
Greenhorn

Joined: Aug 18, 2009
Posts: 26
Hi,

import java.sql.*;

public class Mysqlconnect{
public static void main(String[] args) {
System.out.println("Table Creation Example!");
Connection con = null;
String url = "jdbc:mysql://localhost:3306/";
String dbName = "employee";
String driverName = "com.mysql.jdbc.Driver";
String userName = "root";
String password = "root";
try{
Class.forName(driverName).newInstance();
con = DriverManager.getConnection(url+dbName, userName, password);
try{
Statement st = con.createStatement();
String table = "CREATE TABLE Employee11(Emp_code integer, Emp_name varchar(10))";
st.executeUpdate(table);
System.out.println("Table creation process successfully!");
}
catch(SQLException s){
System.out.println("Table all ready exists!");
}
con.close();
}
catch (Exception e){
e.printStackTrace();
}
}
}

I am getting this exception while running the above program ,i started database server and copied mysql-connector-java-5.1.15-bin.jar in jdk>lib and jre>lib>ext>


Table Creation Example!
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.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Mysqlconnect.main(Mysqlconnect.java:13)


Could you please any one tell me where i did mistake.


With Regards,
Kalai.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

copied mysql-connector-java-5.1.15-bin.jar in jdk>lib and jre>lib>ext>

Remove it ! Your jars have nothing to do in there.

How are you executing your program ? From the command line ?


[My Blog]
All roads lead to JavaRanch
kalai arasan
Greenhorn

Joined: Aug 18, 2009
Posts: 26
Thanks christophe,

Its Working fine
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver