• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointerException for the Date field in ResultSet

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jan!

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

Thank you
Amit
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I have corrected it now.
Thank you all for your help..
 
Jan Cumps
Bartender
Posts: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jan,

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

Regards
Amit
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2661
19
Netbeans IDE C++ Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for posting them, Amit.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic