• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointerException

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am encountering a Nullpointerexception when I try to update a database with:

I have tried many things test or debug that I can't remember, and I can't seem to resaech a solution. Any ideas? The error is occuring on the stmnt.executeUpdate query.

--Added code tags for easier readin - Carl
[ June 07, 2004: Message edited by: Carl Trusiak ]
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is in your try/catch block. You have created new Connection(con) and the Statement(stmnt) ojbects inside the try/catch block. And if remember object creation inside code blocks{} are a candidate from garbage collection and are out of scope outside of the code block.

Your initial declaration:


Should be changed to ...


I hope this helps.
 
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like you are inadvertently redeclaring your Connection and Statement objects inside of your try {} block. In your code:

You created a second set of "con" and "stmnt" variables that are available only within the try {} block. Then your update statement code is using the variables that you created above your try {} block which never got initialized, thus the NullPointerException.

Change your code to this:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic