Can ResultSet.getTimestamp() call return incorrect date-time info?
843854Jun 3 2002 — edited Jun 4 2002
After searching Java forum pages and reading through the JDBC related documentation for a lengthy time, I still could not find a behavior that explains my problem. So, I resort to this mailing list. I hope someone has run into the same problem and has some answers to what I am seeing.. Will appreciate your response in advance!
The problem:
I am using AveConnect that is a JDBC driver certified to work with SQL Server. All of my project's date-time information is converted to UTC. For example, let's say I have a table, Test1 with the following:
create table Test1 (
ID char (10) NOT NULL,
CreateTime date,
Name varchar(20) );
The table was populated with two rows:
('ID-1', '2002-05-29 19:59:21.000', 'ID #1 Name')
('ID-2', '2002-05-29 19:59:54.000', 'ID #2 Name')
The above date-time information would translate to time in milliseconds: 1022702361000 and 1022702394000 respectively. Using the AveConnect's driver, I made a query to the table such as "SELECT * FROM Test1". Naturally, I would have a ResultSet from this. Then, I have the following code:
String ID = null;
long timestamp = 0;
while (result.next())
{
ID = result.getString(1);
timestamp = result.getTimestamp(2).getTime();
System.out.println("ID: " + ID + " StartTime: " + timestamp);
}
From this code, an output was generated, which is like this:
ID: ID-1 StartTime: 1022723961000
ID: ID-2 StartTime: 1022723994000
where 1022723961000 translates to 2002-05-30 01:59:21.000 UTC and
1022723994000 translates to 2002-05-30 01:59:54.000 UTC
As you can see from above, the getTimestamp().getTime() method calls returned values 6 hours more than the original ones. Coincidentally, the SQL Server and the JDBC program both were running in the Mountain time-zone (MDT). As shown above, no time-zone information was applied in getting the milliseconds. Nonetheless, the output tells otherwise.
When I approached to the driver's vendor (AtiNav) with this problem, the tech support told me that I was doing something wrong. I really don't think I was doing anything that is out of ordinary... Is there anything that I missed from the JDBC API?
Thanks,
Hyunjoo