Hello

I am new to java and am having problem loading table numbers from mysql database to tablenumberJComboBox. I am using the load tablenumbers method.

private void loadTableNumbers()
{
// read all table numbers from database
try

{
// obtain all table numbers
myResultSet = myStatement.executeQuery(
"SELECT tableNumber FROM restaurantTables" );

// add numbers to tableNumberJComboBox
while ( myResultSet.next() == true )

{
tableNumberJComboBox.addItem(
String.valueOf( myResultSet.getInt(
"tableNumber" ) ) );

}
myResultSet.close(); // close myResultSet

} // end try

// catch SQLException
catch ( SQLException exception )

{

exception.printStackTrace();

}

} // end method loadTableNumbers

The following errors also appears when i run the code.

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at Restaurant.<init>(Restaurant.java:101)
        at Restaurant.main(Restaurant.java:709)

java.lang.ClassNotFoundException: com.mysql.jdbc.Driver

The JVM is not able to find the above named class when the code at line 101 calls the forName() method. Find the definition for the missing class and put it on the classpath. It's probably in a jar file.

Thanks for your reponse. I checked my classpath and I have the mysql connection bin.jar file.I am still getting the same error. Is the code in my load tablenumbers method accurate?. Thanks

Is the jar file with the class on the classpath?
What paths are on the classpath?
Where is the jar file located?

This article has been dead for over six months. Start a new discussion instead.