pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
setTimestamp(int, Timestamp, Calendar) ignoring time zone?
3+ messages / 2 participants
[nested] [flat]

* setTimestamp(int, Timestamp, Calendar) ignoring time zone?
@ 2013-02-04 04:27  Ian Pilcher <arequipeno@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Ian Pilcher @ 2013-02-04 04:27 UTC (permalink / raw)
  To: pgsql-jdbc

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@gmail.com
Sometimes there's nothing left to do but crash and burn...or die trying.
========================================================================



-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: setTimestamp(int, Timestamp, Calendar) ignoring time zone?
@ 2013-02-04 10:40  Dave Cramer <pg@fastcrypt.com>
  parent: Ian Pilcher <arequipeno@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Dave Cramer @ 2013-02-04 10:40 UTC (permalink / raw)
  To: Ian Pilcher <arequipeno@gmail.com>; +Cc: 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@gmail.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@gmail.com
> Sometimes there's nothing left to do but crash and burn...or die trying.
> ========================================================================
>
>
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: setTimestamp(int, Timestamp, Calendar) ignoring time zone?
@ 2013-02-04 16:36  Ian Pilcher <arequipeno@gmail.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Ian Pilcher @ 2013-02-04 16:36 UTC (permalink / raw)
  To: Dave Cramer <pg@fastcrypt.com>; +Cc: pgsql-jdbc

On 02/04/2013 04:40 AM, Dave Cramer wrote:
> What is the underlying data type ? Timestamp with timezone or without ?

Dave -

The column type is timestamp *with* time zone.  Your question tends to
confirm what I suspected after re-re-re-reading various bits of Javadoc,
along with this:

  http://www.postgresql.org/message-id/4B2F2CED.10400@opencloud.com

I.e. when a java.sql.Timestamp is created from a long, it represents an
absolute point in time, so "taking into account a custom timezone"
doesn't make any sense.  I guess that it might makes sense when using a
timestamp without time zone, although, I'm getting a headache just
trying to think through how that might behave.

Thanks!

-- 
========================================================================
Ian Pilcher                                         arequipeno@gmail.com
Sometimes there's nothing left to do but crash and burn...or die trying.
========================================================================


-- 
Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-jdbc



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2013-02-04 16:36 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-02-04 04:27 setTimestamp(int, Timestamp, Calendar) ignoring time zone? Ian Pilcher <arequipeno@gmail.com>
2013-02-04 10:40 ` Dave Cramer <pg@fastcrypt.com>
2013-02-04 16:36   ` Ian Pilcher <arequipeno@gmail.com>

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