Tech Tip: Timestamp returned by DB2 Java application is off by 1 hour, if it falls in Daylight Savings Range
Swati Thorve 270004FTYS Visits (1402)
Recently I came across a problem, where we saw the timestamp value returned by DB2 Java application was off by 1 hour than the actual timestamp value being stored in database. This was happening only for timestamp values falling in Daylight Savings range. These are the steps I used to reproduce the issue:
1> Create table timestamptest( col1 timestamp)
2> db2 "insert into timestamptest values ('20
3> Select from timestamptest
1 record(s) selected.
4> Wrote a simple Java program to read the timestamp value from database using DB2 Universal JDBC Driver and getString() API.
Running a Java program:
C:\temp\My Samples\Java>java Select
You can see the difference, on database it is saved as 02:49 while Java application is returning 3:49
I was able to isolate the problem from DB2. With no DB2 JDBC driver involved, just with pure Java APIs I was able to reproduce this.
Here is the sample java program I used:
C:\temp\My Samples\Java>java TimeTest
TS2 = 2013-03-10 03:49:14.572013
Researching further, we found according to time and date standards here
So according to this, 2013-03-10 2:49:14.572013 timestamp is non-existing and that's why JRE is correcting it to 2013-03-10 3:49:14.572013.
This is independent of DB2 Java driver and is default behavior of Java.
Hope this helps!