File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Help - Statement error! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Help - Statement error!" Watch "Help - Statement error!" New topic

Help - Statement error!

Lucky Narayan

Joined: Mar 29, 2002
Posts: 4
Hi JDBC gurus,
I am facing a very wierd problem - any help appreciated.
Here is the simple code:
Connection c = DriverManager.getConnection(connURL, dbUserName, dbPassword);
System.out.println("Connected correctly: ");
catch(ClassNotFoundException cnfe)
System.out.println("Error loading driver: " + cnfe);
The above works fine but when I add this line:
Statement stmt = c.createStatement();
it fails, giving the following error:
at myClasses.DbBean.isLoginValid(
pointing to line which has the Statemnt stmt =...
Any ideas why? I am going crazy here
raghavender rao
Ranch Hand

Joined: Jul 20, 2001
Posts: 45
hi ther,
i think Connection object is null...

Rao<BR>Sun Certified Programmer for the Java��� 2 Platform
Jamie Robertson
Ranch Hand

Joined: Jul 09, 2001
Posts: 1879

by the time you use your connection it is out of scope! Thus its reference is null. To get around this, declare your connection outside the try block:

I agree. Here's the link:
subject: Help - Statement error!
It's not a secret anymore!