Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes JDBC and the fly likes Question on Unhandled Exception - please help! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Question on Unhandled Exception - please help!" Watch "Question on Unhandled Exception - please help!" New topic
Author

Question on Unhandled Exception - please help!

Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

In my code I have a method whereby I am trying to connect either to a local server or a mainframe (only this first if statement is shown) but in the BOLDED line below I am getting a "Unhandled exception type ClassNotFoundException". Any help or direction would be appreciated.

Here is my code:

Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
Class.forName throws ClassNotFoundException

So you need to catch it. Or have your method declare that it throws it.
Melinda Savoy
Ranch Hand

Joined: Jun 21, 2005
Posts: 386

Thanks for the reply.

I guess what I don't understand is why I am getting this error. Before putting the if statement around this statement within the try catch I did not get this error. Is it only because I put it in an IF statement? This file is already in the classpath so I do not understand WHY this error now came up.

Any insight would be appreciated.

Thanks again.
Maximilian Xavier Stocker
Ranch Hand

Joined: Sep 20, 2005
Posts: 381
There is more to it than the if statement. If you had the Class forName before then you must have made some other subtle change that gave it problems. Like you used to catch Exception and now you catch SQLException or you used to throws Exception in the method signature but now you only throw SQLException.

Something else changed. Class.forName throws ClassNotFoundException. It did before and it does now. So there was something else other than the if that meant that it wasn't a problem but now it is.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Question on Unhandled Exception - please help!
 
Similar Threads
idiom for finally closing resources
Insert date and time into Oracle database
Help needed on SQL Server Error
Getting Connection Establishing in Linux Server
Newbie help please on SQL connection problem