aspose file tools*
The moose likes JDBC and the fly likes NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "NoClassDefFoundError" Watch "NoClassDefFoundError" New topic
Author

NoClassDefFoundError

joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
Hi Ranchers
i ran the following codes:

url= "jdbc:mysql://localhost:3306/accounts"
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection(url,"root", "password");

System.out.println("COnnection Succeed");
}catch (Exception e) {
System.out.println("Can't connect");
}

this is the Exception i got:
Exception in thread "main" java.lang.NoClassDefFoundError: ConnectionMySQL/java
what is the cause of the exception?.
thanks
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You don't have your driver in your classpath. Check you've got the MySQL JDBC driver jar file(s?) in you classpath.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
i have it.this is where it is found and i set it in my classpath as
C:\j2sdk1.4.1\jre\lib\ext\mysql-connector-java-5.1.5-bin.jar
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Sorry, read your post too quickly. You don't have the class ConnectionMySQL in your classpath. Check this for how to sort it.
joseph okon
Ranch Hand

Joined: Dec 07, 2004
Posts: 63
i have set the classpath properly.
it now gives me


java.sql.SQLException: No suitable driver.


i have try mysql-connector-java-3.1.14
and mysql-connector-java-5.1.5 , i still have the same problem
please can anyboy tell me how to configure apache tomcat to work with mysql

thanks
i'll really appreciate it
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

You get that exception when your URL is wrong, or the Driver class is not registered wit hthe DriverManager. Double check your JDBC URL.

Also you are using Tomcat, which means web application classpath rules apply. If you are calling this code from a servlet your driver will nedd to be in WEB-INF/lib.


i have try mysql-connector-java-3.1.14
and mysql-connector-java-5.1.5 ,

Are you removing the older Jar file before trying the new? It could be your driver is being registered from the older jar and that uses a differernt JDBC url syntax. Java will normally just use the first version of a class it finds on the classpath.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NoClassDefFoundError