aspose file tools*
The moose likes JDBC and the fly likes NullPointerException for the Date field in ResultSet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "NullPointerException for the Date field in ResultSet" Watch "NullPointerException for the Date field in ResultSet" New topic
Author

NullPointerException for the Date field in ResultSet

Amit K Jain
Ranch Hand

Joined: Nov 06, 2008
Posts: 55
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

Joined: Dec 20, 2006
Posts: 2476
    
    7

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?


OCUP UML fundamental and ITIL foundation
youtube channel
Amit K Jain
Ranch Hand

Joined: Nov 06, 2008
Posts: 55
Thank you Jan!

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

Thank you
Amit
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Also you are printing "Null Pointer Exception" when it might be a different exception.
Amit K Jain
Ranch Hand

Joined: Nov 06, 2008
Posts: 55
No, I have corrected it now.
Thank you all for your help..
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2476
    
    7

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

Joined: Nov 06, 2008
Posts: 55
Hi Jan,

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

Regards
Amit
manoj r patil
Ranch Hand

Joined: Jun 06, 2002
Posts: 181
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.


love your job and not your company;
...because you never know when your company will stop loving you!
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2476
    
    7

Thanks for posting them, Amit.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException for the Date field in ResultSet
 
Similar Threads
data in table getting overridden?
data in table getting overridden?
500: SERVER ERROR [AS - 00-0002]
displaying sql query results
java.text.ParseException