The moose likes JDBC 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

Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » JDBC
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.*;
import java.io.*;
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(rs.next()) {
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 java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown 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(JDBCSample.java:17)
Unable to load Driver Class
Kindly let me know how to run the program
Thanking you
Joe Ess

Joined: Oct 29, 2001
Posts: 8876

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

"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[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: http://aspose.com/file-tools
subject: unable to run this program