Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

CLASSPATH problem

843854Jan 23 2003 — edited Jan 23 2003
I have a dummy program listed at the bottom.
This compiles no problem.
I have MySQL set up and running.
When I run it without the CLASSPATH set I get the following error.

Couldn't find DB driver:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

So then I decided to set the CLASSPATH
When I set the classpath in the command prompt:

set CLASSPATH=c:\j2sdk1.4.0_01\jre\lib\ext\mysql-connector-java-2.0.14-bin.jar

then run the program I get the following error

Exception in thread "main" java.lang.NoClassDefFoundError: Sepro

What I'm thinking may be the problem is that I get some default stuff for free if the classpath hasn't been set. If I then set it I lose this free default stuff.

If anyone has any idea it would be greatly appreciated.

Cheers,

elmicko


import java.sql.*;

class Sepro
{

public static void main(String argv[])
{
Connection connection = null;
try {
// Load the JDBC driver
// Class.forName("com.mysql.jdbc.Driver").newInstance();
String driverName = "com.mysql.jdbc.Driver"; // MySQL MM JDBC driver
Class.forName(driverName);

// Create a connection to the database
String serverName = "localhost";
String mydatabase = "Interface";
// jdbc:mysql://[hostname][:port]/[dbname][?param1=value1][�m2=value2
String url = "jdbc:mysql://" + serverName + "/" + mydatabase; // a JDBC url
String username = "Interface";
String password = "";
connection = DriverManager.getConnection(url, username, password);
} catch (ClassNotFoundException e) {
System.out.println("Couldn't find DB driver:" + e);
// Could not find the database driver
} catch (SQLException e) {
System.out.println("Couldn't connect to the DB:" + e);
// Could not connect to the database
}

}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 20 2003
Added on Jan 23 2003
1 comment
185 views