Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

null pointer exception in prepared statement.

 
deepak bhai
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont understand, why this code of prepared statement is giving the error NULL POINTER EXCEPTION

 
Martin Vajsar
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic