Home arrow static arrow Java Programming [Archive] - NoClassDefFoundError
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - NoClassDefFoundError
This topic has 6 replies on 1 page.

Posts:26
Registered: 7/18/04
NoClassDefFoundError  
Aug 3, 2004 3:07 AM



 
Why does this piece of code give me the above error?? The relevant jar file has been added to my classpath via autoexec.bat.

import java.awt.*;
import java.sql.*;

public class Localdemo {

public static void main(String[] args) {
try {

// Register JDBC/mySQL Driver in jdbc DriverManager
Class.forName("com.mysql.jdbc.Driver").newInstance();

// Test with mySQL database ('photos' is a mySQL database)
//String url = "jdbc:mysql:photos";

//try to get a connection to the database
//Connection c = DriverManager.getConnection(url);

//create a statement object
//Statement st = c.createStatement();

//create a resultset to store the results of the query
//ResultSet rs = st.executeQuery("SELECT * FROM competitors");

//ResultSetMetaData md = rs.getMetaData();
//while(rs.next()) { //while records
//for(int i=1; i<= md.getColumnCount(); i++) { // for each field
//System.out.print( rs.getString(i) + " " ); // display field data
//}
//System.out.print("\n");
//}

//rs.close();

}catch(Exception e) {
e.printStackTrace();
}

}//main method

}//localdemo class

 

Posts:319
Registered: 11/8/00
Re: NoClassDefFoundError  
Aug 3, 2004 3:31 AM (reply 1 of 6)



 
What is the error message actually saying?

is the Driver class in your class path if you type
echo %CLASSPATH%


ps Please follow the formatting guidelines at http://forum.java.sun.com/features.jsp#Formatting when posting code.
 

Posts:26
Registered: 7/18/04
Re: NoClassDefFoundError  
Aug 3, 2004 3:55 AM (reply 2 of 6)



 
It says

c:\j2sdk1.4.2_03\jre\lib\ext\mysql-connector-java-3.0.14-production-bin.jar;%CLASSPATH%
 

Posts:319
Registered: 11/8/00
Re: NoClassDefFoundError  
Aug 3, 2004 4:06 AM (reply 3 of 6)



 
c:\j2sdk1.4.2_03\jre\lib\ext\mysql-connector-java-3.0.14-production-bin.jar;%CLASSPATH%

The current path is not in that classpath. don't know why %CLASSPATH% has not been evaluated but the Localdemo needs to be in the classpath as well

make sure '.' i.e. current directory is in your classpath
 

Posts:26
Registered: 7/18/04
Re: NoClassDefFoundError  
Aug 3, 2004 4:21 AM (reply 4 of 6)



 
Any good web material on this classpath thingy?

I've been learning java for a while now and no-one has told me why i need it/what it does/how to set it etc..
 

Posts:319
Registered: 11/8/00
Re: NoClassDefFoundError  
Aug 3, 2004 4:26 AM (reply 5 of 6)



 
Here you go:
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html
http://wiki.java.net/bin/view/Javapedia/ClassPath
 

Posts:26
Registered: 7/18/04
Re: NoClassDefFoundError  
Aug 3, 2004 4:48 AM (reply 6 of 6)



 
Cheers, thanks for your help.
 
This topic has 6 replies on 1 page.