Issuing the following SQL generates different results thru PL/SQL, ODBC and JDBC:
select sysdate from dual
When running it on PL/SQL or ODBC, the date and time is correct. On JDBC it comes with an hour less. It seems that it is not considering daylight savings.
For example, on PL/SQL the result is 2012-11-05 16:53:53.0
and on JDBC it is 2012-11-05 15:53:53.0
.
It happens only on some databases. Changing the database timezone (select dbtimezone from dual
) doesn't seems to affect the results.
The command is executing on Brazil. Raw GMT offset is -03:00, current offset is -02:00 because of daylight savings.
The timezone database of the client JVM is up-to-date.
To diagnose the "wrong" result from database, just print the result:
((OracleResultSet) statement.executeQuery("select sysdate from dual")).getTIMESTAMP(1).toString();
Oracle's TIMESTAMP
toString
method do not rely on timezone information. The JVM's timezone may only affect the result before the creation of the TIMESTAMP
, i.e. while reading from the network and transforming it into a representation in Java.
Tests on changing both client and database server time configuration:
SYSDATE
always return the date/time resolved in the database server, the client JVM'suser.timezone
option and client's machine time configuration do not matter.- On the other hand, getting
SYSTIMESTAMP
is resolved using both timezone informations: looks like it gets the date and time from server in UTC and then apply the timezone in the client to get a local date and time.
Client is running Windows, server is running Linux.
To get things more weird, issuing a TO_CHAR
yield the wrong result too:
select TO_CHAR(SYSDATE, 'DD/MM/YYYY HH24:MI:SS') from dual
- Directly on Oracle:
06/11/2012, 10:38:49
- On Java:
06/11/2012 09:38:49
Oracle servers:
[root@oracle1 ~]# cat /etc/sysconfig/clock
ZONE="America/Sao_Paulo"
UTC=false
ARC=false
[root@oracle1 ~]# echo $TZ
[root@oracle1 ~]# date
Tue Nov 13 14:58:38 BRST 2012
[root@oracle1 ~]#
[root@oracle2 ~]# cat /etc/sysconfig/clock
ZONE="America/Sao_Paulo"
UTC=false
ARC=false
[root@oracle2 ~]# echo $TZ
[root@oracle2 ~]# date
Tue Nov 13 14:59:58 BRST 2012
[root@oracle2 ~]#
Any thoughts? What info or configuration should I collect from the database to diagnose and solve this problem?
getdbdatetime
is not a predefined function in Oracle. I'm assuming it is a function that you created. Can you post the definition of that function? – Justin Cave