Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ClassNotFoundException out of nowhere!!

 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I am using MySQL, all the connection and queries have been working fine for quite sometime and than suddenly when i run my code today it gives me ClassNotFoundException, all the server settings are the same. I am using Tomcat4.
I am using a DBHandler class that creates and returns a connection object.
Its very frustrating, that it suddenly stops working.
Please HELP!!!
Gul
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34396
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Has your system level classpath changed recently?
 
Gary Joehlin
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing that tripped me up was that unbeknownst to me, this error is also caused by a firewall not letting the connection get through. Check if a new software firewall has been installed and/or that if it has 'always' been there, that parameters haven't changed pertaining to communications from your 'application' being BLOCKED, in both directions.
Along the same line as the classpath issue, that is another item that should be on your check list, did it get updated in one place but not the other?
Another question to ask is: "Did the code get changed?" Really, then analyze any refrences to the driver and its class.
I hope these few items will give you some insight on what I have, as a greenhorn, found in my frustrations.
Regards,
Gary J.
COS
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The most frustrated i m about is that its working in some parts, i have just added a new module to it yesterday. All my database code is seperate and has not been changed. NO recent classpath changes also and database settings are also the same as one month before.
The parts it is working in are some of the select queries. they are working fine as before but the insert and update queries when they try to fetch the connection from the same dbHandler class it returns a null connection.
Thanks for the tips by the way
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my DBHandler class for getting the connection
/////////////////////////////////////////////
public class DBHandler {

private String dbClass="org.gjt.mm.mysql.Driver";
// .jar file for driver added to classpath
private String dbURL="jdbc:mysql://localhost:3306/dbName?user=admin&password=admin";

private Connection dbCon;
/** Creates a new instance of DBHandler */
public DBHandler() {
}

public java.sql.Connection getDbConnection()throws SQLException {
try{
Class.forName(dbClass).newInstance();
dbCon= DriverManager.getConnection(dbURL);
}catch(ClassNotFoundException e){

System.out.println("null Connection");
}catch(Exception e){
dbCon=null;
System.out.println("Instantiation or General Exception "+e.getMessage());
}

return dbCon;
}

public void close(java.sql.Connection con)throws SQLException{
try{
con.close();
}catch(SQLException e){System.out.println("Unable to Close the Connection");}
}

}
/////////////////////////////////////////////////////////
Each time i try to access DBHandler.getDbConnection it gives me the classnotfound exception.
I just checked my database out, and i hope u believe me that at database level all the data is updated and inserted but still my class throws a ClassNotFoundException. and i have no ideawhats going on here, coz it shouldnt be able to access the database if the connection is null:
[ September 20, 2003: Message edited by: pervaiz gul ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic