Get timestamp with timezone from Oracle
Hi!
I've a table with TIMESTAMP(6) WITH TIME ZONE type.
When I retrieve data:
java.sql.Timestamp dbSqlTimestamp_in = rs.getTimestamp(1);
java.sql.Timestamp dbSqlTimestamp_out = rs.getTimestamp(2);
System.out.println("dbSqlTimestamp=" + dbSqlTimestamp_in);
System.out.println("dbSqlTimestamp=" + dbSqlTimestamp_out);
i don't get TZ:
dbSqlTimestamp=2007-07-18 09:57:59.0
dbSqlTimestamp=2007-07-17 15:05:29.0
Why?
Could you help to get timestamp with time zone from Oracle?
Thanks a lot
[566 byte] By [
vilacovaa] at [2007-11-27 10:55:48]

# 1
> don't get TZ:
> bSqlTimestamp=2007-07-18 09:57:59.0
> dbSqlTimestamp=2007-07-17 15:05:29.0
> Why?
What are you expecting to get based on the java.sql.Timestamp API?
This is what I get in SQL*Plus (which is using the database timezone):
SELECT SYSTIMESTAMP FROM DUAL;
18-JUL-07 10.53.13.574000 AM -07:00
The returned row looks like it is formatted as a String (by default). Would it help you to retrieve the information as a String and then you could process it accordingly?
Here is a forum post that discusses the issue. There isn't a definitie answer in the postings:
http://forum.java.sun.com/thread.jspa?threadID=702531&start=15
It might help to know more about what you are trying to do (what your expecations are).
# 2
I'm expecting to get the same result than sqlplus. somenting like:
18-JUL-07 10.53.13.574000 AM -07:00
I need to know exactaly the timezone in java application.
# 3
> I'm expecting to get the same result than sqlplus.
> somenting like:
> 18-JUL-07 10.53.13.574000 AM -07:00
>
> I need to know exactaly the timezone in java
> application.
When I wrote:
"The returned row looks like it is formatted as a String (by default). Would it help you to retrieve the information as a String and then you could process it accordingly?"
Did you understand this?
Did you try this to see if it would resolve your issue?
If you had tried it you would find that a String similar to what you get from SQL*Plus is returned. Here are what the two strings look like, the first from SQL*Plus the 2nd from JDBC:
18-JUL-07 03.08.54.599000 PM -05:00
2007-7-18 15.7.58.599000000 -5:0
These two Strings look like exactly the same information just formatted a little differently. This is using default formatting in both cases. You could choose to format the String any way you want. Oracle is very flexible in that regard.
These are the type of things you can try on your own to see if they work. That's why I suggested retrieving the timestamp as a String in the first place. I followed through this time but sometimes you will get things done quicker if you take the suggestions and try them before asking more questions.
Here is an incomplete code snippet if you want to try it yourself:
String select = "SELECT SYSTIMESTAMP FROM DUAL";
DriverManager.registerDriver (new oracle.jdbc.driver.OracleDriver());
Connection conn = DriverManager.getConnection ("jdbc:oracle:thin:@Archer:1521:cltdb01",
"userid",
"password");
Statement statement = conn.createStatement();
ResultSet rs = statement.executeQuery(select);
rs.next();
String tz = rs.getString(1);
System.out.println(tz);
statement.close();
conn.close();
Does this information tell you what you need to know?