• Post Reply Bookmark Topic Watch Topic
  • New Topic

It gives Class not found exception for mySQL  RSS feed

Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I just wrote a simple JDBC program as follows.

import java.sql.*;

public class LoginDAO {
Connection con=null;
Statement st = null;
ResultSet rs= null;

public static void main(String arg[])
LoginDAO da = new LoginDAO();


public LoginDAO() {


public void login()
System.out.println("***********************************THE DRIVER IS REGISTERED********************************");
System.out.println("***********************************THE CONNECTION IS SET********************************");
st = con.createStatement();
rs= st.executeQuery("SELECT * FROM login_valid");
while (rs.next())
int number = rs.getInt("login_valid#");
String userid = rs.getString("userid");
String password = rs.getString("password");
System.out.println(number + " " + userid + " " + password);

catch(Exception e)

The program compiles nicely but when trying to run it gives the following exception
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader$1.run(URLClassLoader.java:198)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:186)
at java.lang.ClassLoader.loadClass(ClassLoader.java:299)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:265)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:315)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:140)
at LoginDAO.login(LoginDAO.java:25)
at LoginDAO.main(LoginDAO.java:13)

I have removed and reinstalled mysql and still the error is there.
Is there anything i am missing on.
Please give suggestion

With Regards
S.R.K.Vivek Raju.
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to add the MySQL JDBC driver to your CLASSPATH.
The driver is usually named something like : mysql-connector-java-3.0.9-stable-bin.jar
Either add it explicitly to your CLASSPATH or add it into JAVA_HOME/jre/lib/ext directory.
and can be downloaded if you have not already got it from http://www.mysql.com/products/connector/j/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!