We help IT Professionals succeed at work.

how to update a null date in JAVA

lmymusic2000
lmymusic2000 asked
on
Medium Priority
292 Views
Last Modified: 2012-05-12
I would like to ask JAVA developers this question. I encounter a situation where my java program failed to read a null date in a Oracle table. The compile error is 'JAVA NULL POINTER EXCEPTION'. What should be the logic in code to handle this situation. I am initialize my date field as date. I try to initialize my date field as string to get around this issue and not working either. All input welcome. Thanks
Comment
Watch Question

Awarded 2011
Awarded 2011
Commented:
you should probably check rs.wasNull() immedaitely adter trying to read the dtae form resultset
Don't use strings instead of dates
Post your code which casues the problem
CERTIFIED EXPERT
Top Expert 2016

Commented:
You could try the following or ResultSet.wasNull
Object date = resultSet.getObject(n);
if (date == null) {
   // Take action
}

Open in new window

Awarded 2011
Awarded 2011

Commented:
Post your code and we'll try to find the solution.
This is definitely better than trying to store date as string - sooner or later
you'll regret doing it in your database - I had a few cases like that in the old tables - since then
trying to cope with this unfortuinate decision

and I'm sure we'll find something how to deal with null pointer
Commented:
If you need only to compile successfully your application and don't need to know when that field is null you could change your query:
 from   "select ... field_with_date ..."
 to   "select ... nvl(field_with_date, to_date('01.01.1901','dd.MM.yyyy')) as field_with_date..."

The null fields from result would be replaced by that date "01.01.1901".

Author

Commented:
I've found the solution on my own. Thank you for all of your respond

Author

Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for lmymusic2000's comment http:/Q_27430686.html#37126318

for the following reason:

I've found the solutions. Thank you for all the responds.
CERTIFIED EXPERT
Top Expert 2016

Commented:
>>I've found the solution on my own. Thank you for all of your respond

Sorry - that's not an acceptable response

Author

Commented:
Hi Mod,
Actually other team members in this project found the solution to this question and I do not know what is the actual coding behind this. Please close this question and thank you for all the  respond
CERTIFIED EXPERT
Top Expert 2016

Commented:
Sorry that's not acceptable either. No refund

Explore More ContentExplore courses, solutions, and other research materials related to this topic.