Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problems compiling code for a MySQL connection

Status
Not open for further replies.

kirkegaard

Technical User
Nov 18, 2001
1
DK
Java throws the following exception when I try to run the code: Exception in thread "main" java.lang.NoClassDefFoundError: DBConnect

I don't know what the problem is. My classpath should be in order, since it doesn't have to point to anything else than the JDBC driver for MySQL to work right?

import java.sql.*;

public class DBConnect {
public static void main(String[] args) {

try {

Class.forName("org.gjt.mm.mysql.Driver");

String sourceURL = "jdbc:mysql:mad:fyr.cs.auc.dk:3306:e1202";
String user = "xxxxxx";
String password = "xxxxxx";

Connection databaseConnection = DriverManager.getConnection(sourceURL, user, password);

System.out.println("Connection established");

databaseConnection.close();
}
catch (ClassNotFoundException cnfe) {
System.err.println(cnfe);
}
catch (SQLException sqle) {
System.err.println(sqle);
}
}
}
 
The NoClassDefFoundError that throws the JVM refers that your class is not in the execution classpath.

Then compile the class using javac -classpath jdk_directory\lib\classes.zip DBConnect.java.

After you compile the class, execute your class using java -classpath jdk_directory\lib\classes.zip;your_class_path DBConnect

I supposed you use a version jdk1.1.x; if you use Java2 the path of the basic API's is jdk_directory\src.jar

Regards

Joan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top