Meaningless Drivel is fun!
The moose likes JDBC and Relational Databases and the fly likes unable to run this program 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 "unable to run this program" Watch "unable to run this program" New topic

unable to run this program

nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
hi all,
I am just trying to get a feel of connecting mysql to java and I am having a horrid time.The code is...
import java.sql.*;
import java.sql.*;
public class JDBCSample{
public static void main(String[] args) {
try {
catch (Exception e) {
System.out.println("Unable to load Driver Class");

try {
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test");
Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery("SELECT * FROM pet");
while( {
catch (SQLException se) {
System.out.println("SQL Exception: " + se.getMessage());
} // End of main
} // End of class JDBCSample
The error I am getting is ....

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at$ Source)
at Method)
at Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at JDBCSample.main(
Unable to load Driver Class
Kindly let me know how to run the program
Thanking you
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

According to the MySQL Connector/J documentation, you have to put the connector jar file in the classpath.

[How To Ask Questions On JavaRanch]
nash avin
Ranch Hand

Joined: Nov 13, 2003
Posts: 96
Thanks for the prompt information.It was silly of me wasnt it?.Will get in touch with more questions.
I agree. Here's the link:
subject: unable to run this program
It's not a secret anymore!