• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError

 
joseph okon
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have your driver in your classpath. Check you've got the MySQL JDBC driver jar file(s?) in you classpath.
 
joseph okon
Ranch Hand
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 63
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic