From: Kris Jurka <books@ejurka.com>
To: Chip Gobs <chip.gobs@noaa.gov>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Timestamp without timezone issue
Date: Wed, 5 Dec 2007 10:53:11 -0500 (EST)
Message-ID: <Pine.BSO.4.64.0712051048150.24930@leary.csoft.net> (raw)
In-Reply-To: <4755B864.4000203@noaa.gov>
References: <4755B864.4000203@noaa.gov>
On Tue, 4 Dec 2007, Chip Gobs wrote:
> We recently changed from using PostgreSQL 7.4.8 to 8.2.5 and switched the
> JDBC driver to the 8.2.506 version from the 74.215 version. We are and have
> been using build 1.5.0_04-b05 of the J2SE since before our Postgres version
> change.
>
> The column obstime is of type timestamp without timezone. After using psql
> to experiment, it appears that the -06 is being ignored and the time in the
> value assignment part of the update statement is being considered as
> 10:00:00 UTC instead of 16:00:00 UTC.
>
> The following did not work:
>
> TimeZone tz = TimeZone.getTimeZone("UTC");
> Calendar cal = Calendar.getInstance(tz);
> Timestamp timestamp = new Timestamp(timeInMillis);
> statement.setTimestamp(index, timestamp , cal);
>
Could you be more clear on why this doesn't work? The attached test case
seems like it is working as you desire.
Kris Jurka
Attachments:TS.java (text/plain, 965B) download
import java.sql.*;
import java.util.*;
public class TS {
public static void main(String args[]) throws Exception {
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection("jdbc:postgresql://localhost:5830/jurka?loglevel=0","jurka","");
Timestamp ts = new Timestamp(System.currentTimeMillis());
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
System.out.println(ts);
PreparedStatement pstmt = conn.prepareStatement("SELECT ?::timestamp, ?::timestamp");
pstmt.setTimestamp(1, ts);
pstmt.setTimestamp(2, ts, cal);
System.out.println(pstmt);
ResultSet rs = pstmt.executeQuery();
rs.next();
System.out.println(rs.getString(1));
System.out.println(rs.getString(2));
Timestamp ts1 = rs.getTimestamp(1);
Timestamp ts2 = rs.getTimestamp(2,cal);
System.out.println(ts1);
System.out.println(ts2);
rs.close();
pstmt.close();
conn.close();
}
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: books@ejurka.com, chip.gobs@noaa.gov
Subject: Re: Timestamp without timezone issue
In-Reply-To: <Pine.BSO.4.64.0712051048150.24930@leary.csoft.net>
References: <4755B864.4000203@noaa.gov> <Pine.BSO.4.64.0712051048150.24930@leary.csoft.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox