Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> JDBC with Timestamp with local time zone column

JDBC with Timestamp with local time zone column

From: <thtsang_yh_at_yahoo.com.hk>
Date: 25 Feb 2005 19:45:53 -0800
Message-ID: <1109389553.433904.240820@f14g2000cwb.googlegroups.com>


I am using JDK 1.3 and Oracle 8i JDBC driver against a 9iR2 DB. And I am having problem with 'Timestamp with local time zone' columns. And actually, I've tested the 9i JDBC driver (Oracle9i 9.2.0.5, freshly downloaded from Oracle) and the same problem occur.

Both the DB sever and client environment have set the timezone to HongKong or equivalent (GMT+8). I have a table with the following data:

SQL> select * from timezone_test;

TS                                  D
----------------------------------- ---------------------
26-FEB-05 11.06.28.6042310 AM       26-FEB-05 11.06.28 AM

I run the following SQL in a java program and retrieve the results using getString().

select cast(ts as date) ts_d, d d1
from timezone_test

If I use 8i/9i JDBC driver, the result is ts_d: 2005-02-26 03:06:29.0
d: 2005-02-26 11:06:28.0
(Seems Oracle is assuming I am in London)

If I use 10g JDBC driver, the result is
ts_d: 2005-02-26 11:06:29.0
d: 2005-02-26 11:06:28.0

The SQL returns the following if run in SQL*Plus

TS_D                        D1
--------------------------- ---------------------------
26-FEB-05 11.06.29 AM       26-FEB-05 11.06.28 AM

The actual JAVA code sniplet:

String sqlString = "select cast(ts as date) ts_d, d d1 "; sqlString += "from timezone_test ";
System.out.println(sqlString);
pstmt = conn.prepareStatement(sqlString); rs = pstmt.executeQuery();
rs.next();
System.out.println("ts_d: " + rs.getString("ts_d")); System.out.println("d: " + rs.getString("d1"));

getTimestamp() seems to give the correct result with 9i JDBC. However, with the 8i JDBC driver, getTimestamp() throws exception. Received on Fri Feb 25 2005 - 21:45:53 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US