aspose file tools*
The moose likes JDBC 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
Bookmark "Help - Statement error!" Watch "Help - Statement error!" New topic
Author

Help - Statement error!

Lucky Narayan
Greenhorn

Joined: Mar 29, 2002
Posts: 4
Hi JDBC gurus,
I am facing a very wierd problem - any help appreciated.
Here is the simple code:
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
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:
java.lang.NullPointerException
at myClasses.DbBean.isLoginValid(DbBean.java:107)
pointing to line which has the Statemnt stmt =...
Any ideas why? I am going crazy here
Thanks!
raghavender rao
Ranch Hand

Joined: Jul 20, 2001
Posts: 45
hi ther,
i think Connection object is null...
try
System.out.println(con);


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:

Jamie
 
 
subject: Help - Statement error!