Tuesday, 7 July 2009

Never trust Database Developer GUIs

Today in our project we had one LIVE issue in our code.

Java Code is throwing exception and suggesting us it is unable to calculate number of years between start date and end date.

But alas our database records looks fine when opened from Oracle SQLDeveloper.

select start_date,end_date from dummy
01-JAN-93 03-DEC-02

We are suprised as it is clear that end_date is greater than start_end and how come java code is unable to digest this issue.


// startDate,endDate values are retrieved from the above dummy table.
Calendar cal = Calendar.getInstance();
cal.setTime(startDate);
int fromYear = cal.get(Calendar.YEAR);
cal.setTime(endDate);
int toYear = cal.get(Calendar.YEAR);



List<String> searchYears = new ArrayList<String>();
for (int i=fromYear;i<toYear+1;i++)
{
// do something
}



Then finally after few hours of struggles our Database Developer Dave Murton have found out the problem.

When he ran from SQL Prompt as he wont trust GUI's much we found out that to_date value is infact 0002.

Ooops... Never trust GUI's

1 comment:

Prasad Chitta said...

you need to set the format... if you just use a 2 digit year format, this is what happens.....