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


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "ClassNotFoundException out of nowhere!! " Watch "ClassNotFoundException out of nowhere!! " New topic
Author

ClassNotFoundException out of nowhere!!

Gul Khan
Ranch Hand

Joined: Sep 03, 2003
Posts: 173
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
internet detective
Marshal

Joined: May 26, 2003
Posts: 29287
    
140

Has your system level classpath changed recently?


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Gary Joehlin
Greenhorn

Joined: Sep 18, 2003
Posts: 16
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

Joined: Sep 03, 2003
Posts: 173
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

Joined: Sep 03, 2003
Posts: 173
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassNotFoundException out of nowhere!!
 
Similar Threads
start jboss-4.2.2.GA in windows service
JDBC That fails in one workspace but works in another
Running Java program using .bat file.
Tomcat and jdbc/odbc
Jboss windows service