wood burning stoves 2.0*
The moose likes JDBC 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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "It gives Class not found exception for mySQL" Watch "It gives Class not found exception for mySQL" New topic
Author

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();

da.login();
}

public LoginDAO() {
super();

}

public void login()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
System.out.println("***********************************THE DRIVER IS REGISTERED********************************");
con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/eeeha_database");
System.out.println("***********************************************"+con+"************************************");
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);
}
rs.close();
st.close();
con.close();


}
catch(Exception e)
{
e.printStackTrace();
}
}
}


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

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 http://www.mysql.com/products/connector/j/


Free Java Database Connection Pooling Software<br /><a href="http://www.primrose.org.uk" target="_blank" rel="nofollow">primrose.org.uk</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: It gives Class not found exception for mySQL