Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException for the Date field in ResultSet

 
Amit K Jain
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I have to get the value from the first record in the ResulstSet for Date field in jsp. I have to print a message in jsp if the date field is null but it throws NullPointer Exception and I see the message in server console that I have written in catch block. Can you please help me with this? Below is the code snippet.
================================================================
ResultSet sentNotification = pn_bean.getStatus(itemId, con);
if(sentNotification.next(){
try{
if(sentNotification .getTimestamp("date_notification_sent") != null){
date_notification= sentNotification.getTimestamp("date_notification_sent"); // date_notification_sent is Date filed in DB table
}
}catch(Exception e){
System.out.println("NullPointer Exception")
}
}

if(date_notification){
"PRINT MESSAGE"
}
=================================================================

Thanks in advance
/Amit
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't hide the exception. Print the exception message in the catch block in stead of "NullPointer Exception".
At what line is the exception occurring?
sentNotification.next() should be in your try block, as it can throw an SQLException.
Are you shure that your ResultSet supports that you call getTimestamp("date_notification_sent") twice?
 
Amit K Jain
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jan!

Using the getTimeStamp twice was the problem. It is fixed now .

Thank you
Amit
 
Campbell Ritchie
Sheriff
Pie
Posts: 49460
64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also you are printing "Null Pointer Exception" when it might be a different exception.
 
Amit K Jain
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I have corrected it now.
Thank you all for your help..
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit.

We are discussing the error you had in this thread.
Would you be so kind to tell us the java version, the database & version and the jdbc driver & version you were using?
 
Amit K Jain
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jan,

Here are the details:
Java Version: 1.5
Database Oracle 10g
Hibernate 3.1.3

Regards
Amit
 
manoj r patil
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this on Oracle 10g with jdk1.5 and it worked for me.

Amit, in the example you have illustrated, I don't think you are using hibernate, so I didn't bother about this.
 
Jan Cumps
Bartender
Posts: 2588
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting them, Amit.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic