• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Help - Statement error!

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ther,
i think Connection object is null...
try
System.out.println(con);
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
permaculture is giving a gift to your future self. After reading this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic