File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes It gives Class not found exception for mySQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "It gives Class not found exception for mySQL" Watch "It gives Class not found exception for mySQL" New topic

It gives Class not found exception for mySQL

S.R.K.Vivek Raju
Ranch Hand

Joined: Sep 23, 2004
Posts: 58
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 (
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 Method)
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
at java.lang.ClassLoader.loadClassInternal(
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(
at LoginDAO.login(
at LoginDAO.main(

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.
Ben Keeping

Joined: Jan 19, 2005
Posts: 10
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

Free Java Database Connection Pooling Software<br /><a href="" target="_blank" rel="nofollow"></a>
I agree. Here's the link:
subject: It gives Class not found exception for mySQL
It's not a secret anymore!