Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

It gives Class not found exception for mySQL

 
S.R.K.Vivek Raju
Ranch Hand
Posts: 58
  • 0
  • 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();

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
Posts: 10
  • 0
  • 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