aspose file tools*
The moose likes JDBC and the fly likes null pointer exception in prepared statement. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "null pointer exception in prepared statement." Watch "null pointer exception in prepared statement." New topic
Author

null pointer exception in prepared statement.

deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
I dont understand, why this code of prepared statement is giving the error NULL POINTER EXCEPTION

Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

Neither do I - there is no PreparedStatement in the fragment you're giving us. So, please post your real code.

(It's great you're using the code tags, but it would be better still if you kept the lines reasonably short -- see UseCodeTags.)
deepak bhai
Ranch Hand

Joined: Apr 22, 2011
Posts: 33
this is my real code. I used system.out.print to see what's happening in preparedStatement but its not working, and system.out.println statement itself is throwing null pointer exception


Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

Well, the text of the command is just that - the text. It is a String literal. It cannot ever be null. That it is also is a SQL command to be used with PreparedStatement is irrelevant. I don't see how System.out.println("some String literal") could ever throw a NPE (NullPointerException).

So I'd say that the NPE comes from a different line in your program. You can easily try that - just comment out the System.out.println and try again. My bet is that the error will be exactly the same - even the line numbers in the stack trace won't change.

You should be able to identify the exact line where the exception occurred from the stack trace.
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

Is the "con" variable null? It is a common anti-pattern to catch exceptions and do nothing. Which could result in null being returned from make connection and explain your null pointer.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null pointer exception in prepared statement.