Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Beginning Java and the fly likes NullPointerException on PreparedStatement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NullPointerException on PreparedStatement" Watch "NullPointerException on PreparedStatement" New topic
Author

NullPointerException on PreparedStatement

Peter Dennis
Greenhorn

Joined: Nov 30, 2008
Posts: 12
Hi All,

Could someone please tell me what kind of conditions could cause the NullPointerException?

My code looks like this:



Many thanks,

Peter.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 41601
    
  31
Welcome to JavaRanch

You are not getting an SQLException anywhere?
As you doubtless already know, NullPointerExceptions (NPEs) are very common and very annoying. I seem to write about them all the time, most recently here (note there is a mistake which I picked up later).

Are you sure your connection isn't null?

I presume the SQL is correct; it looks all right, and it would produce an SQLException rather than an NPE.

Go through what I wrote, and add a line just before where you get your Exception which prints whether the connection is null. See whether that helps.

I probably can't help any more now; it is too late, but there will be other people around.
Peter Dennis
Greenhorn

Joined: Nov 30, 2008
Posts: 12
Thanks very much for that. The null connection was the problem.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 41601
    
  31
You're welcome. It was easy to guess from the info you provided.
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: NullPointerException on PreparedStatement