Re: setTimestamp(int, Timestamp, Calendar) ignoring time zone?

From: Dave Cramer <pg(at)fastcrypt(dot)com>
To: Ian Pilcher <arequipeno(at)gmail(dot)com>
Cc: List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: setTimestamp(int, Timestamp, Calendar) ignoring time zone?
Date: 2013-02-04 10:40:52
Message-ID: CADK3HHLFYFMCPnx-F0UdUhit0jZoNoejHL_mithVtaiiA-H+aQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Ian,

What is the underlying data type ? Timestamp with timezone or without ?

Dave Cramer

dave.cramer(at)credativ(dot)ca
http://www.credativ.ca

On Sun, Feb 3, 2013 at 11:27 PM, Ian Pilcher <arequipeno(at)gmail(dot)com> wrote:

> I am trying to use a Calendar parameter to setTimestamp. From what I've
> read, using a Calendar with a non-default time zone should change the
> value that is written to my table:
>
> > public static void main(String[] args) throws Exception
> > {
> > System.out.println(
> > "System time zone is " + TimeZone.getDefault().getID());
> > Calendar c = Calendar.getInstance(
> > TimeZone.getTimeZone("America/Chicago"));
> > Class.forName(JDBC_DRIVER_CLASS);
> > Connection db =
> > DriverManager.getConnection(DB_URL, DB_USER, DB_PASSWD);
> > Statement s = db.createStatement();
> > s.execute("DELETE FROM foo");
> > PreparedStatement ps =
> > db.prepareStatement("INSERT INTO foo (bar) VALUES (?)");
> > ps.setTimestamp(1, Timestamp.valueOf("2013-02-01 00:00:00"));
> > ps.execute();
> > ps.setTimestamp(1, Timestamp.valueOf("2013-02-01 00:00:00"), c);
> > ps.execute();
> > ResultSet rs = s.executeQuery("SELECT * FROM foo");
> > while (rs.next()) {
> > System.out.println(rs.getTimestamp(1));
> > }
> > db.close();
> > }
>
> The output from the program is:
>
> > System time zone is America/New_York
> > 2013-02-01 00:00:00.0
> > 2013-02-01 00:00:00.0
>
> Is this a bug/missing feature in the driver, or am I doing something
> wrong?
>
> Thanks!
>
> --
> ========================================================================
> Ian Pilcher arequipeno(at)gmail(dot)com
> Sometimes there's nothing left to do but crash and burn...or die trying.
> ========================================================================
>
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Hari Babu 2013-02-04 12:46:07 Re: [GENERAL] JDBC connection test with SSL on PG 9.2.1 server
Previous Message Steven Schlansker 2013-02-04 05:40:38 Re: Extracting more useful information from PSQLException