• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

It gives Class not found exception for mySQL

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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/
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic