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

jdbc null pointer exception

 
Kshitiz Agarwal
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am facing a null pointer exception in resultset:

java.lang.NullPointerException
at com.mysql.jdbc.ResultSet.buildIndexMapping(ResultSet.java:627)
at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:963)
at com.mysql.jdbc.ResultSet.getTimestamp(ResultSet.java:6256)
at com.infosys.ingreen.middleware.jpaservice.LiveDataService.getTimestampList(LiveDataService.java:111)
at com.infosys.ingreen.middleware.jpamanager.DataManager.saveData(DataManager.java:42)
at com.infosys.ingreen.middleware.service.DataCollection.saveLiveData(DataCollection.java:214)

My code is:



If I am already checking for null pointer in resultset.getTimestamp(), why it is throwing error???
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not actually checking for null because || is a short circuit operator.



that will skip the second part of the if statement if resultSet.next is true.

even then,



will only check the first result and then follow with a loop thru all the other results, missing the null check again.

I would get rid of the if statement and check for a null manual timestamp inside the while loop.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic