This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException

 
Jonathan Buchanan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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 ]
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • 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.
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • 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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic