pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dave Cramer <pg@fastcrypt.com>
To: Kevin Grittner <Kevin.Grittner@wicourts.gov>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Timestamp Conversion Woes Redux
Date: Fri, 22 Jul 2005 08:45:42 -0400
Message-ID: <2B25D0C2-4C32-4641-91B7-48DAA498B9C9@fastcrypt.com> (raw)
In-Reply-To: <s2dfc8ca.027@gwmta.wicourts.gov>
References: <s2dfc8ca.027@gwmta.wicourts.gov>

I looked for this in the trail, and couldn't find it.
So here it is verbatim

setTimestamp with a calendar

Sets parameter number parameterIndex to x. When the DBMS does not  
store time zone information, the driver will use cal to construct a  
JDBC Timestamp value which it then sends to the database. With a  
Calendar object the driver can calculate the Timestamp object taking  
into account a custom time zone. If no Calendar object is specified,  
the driver uses the time zone of the Virtual Machine that is running  
the application.


So my interpretation is.

If we are storing a timestamptz then ignore cal and use the server  
time zone
If we are storing a timestamp then use cal to calculate the  
timestamp; if cal is null then use the JVM's  time zone.

getTimestamp is a little less clear

When a getTimestamp method is called, the driver converts a JDBC  
TIMESTAMP instance, which is generally a string, to a  
java.sql.Timestamp object, which is a milliseconds value. In order to  
calculate the milliseconds, the driver takes into account the time  
zone, information a DBMS may or may not store. Because a Timestamp  
object itself has no way to keep track of time zone information, the  
driver relies on a java.util.Calendar object to get this information.  
If no Calendar object
is supplied the the driver will use the default Calendar, whose time  
zone is that of the JVM that is running the application. If the DBMS   
does provide time zone information, the driver will simply use that  
and ignore a Calendar object that may be passed to it. Therefore to  
be portable, an application should supply a Calendar object to a  
getTimestamp method thereby not relying on the DBMS to supply a time  
zone but still being able to use the time zone supplied by a DBMS  
when one is available.


I'm unclear whether "provides time zone information" means the server  
time zone, or time zone returned in the data.

That aside:

If the server provides time zone info, use that to create the  
timestamp, regardless of calendar supplied
if the server does not provide time zone info, use calendar supplied,  
if that is null or not supplied then use JVM calendar.

Dave


On 21-Jul-05, at 5:09 PM, Kevin Grittner wrote:

> Could you post the URL so that I can find the reference without
> searching the whole trail?  (My apologies if I missed this in an  
> earlier
> message -- there have been so many on this topic that I sometimes
> skimmed.)
>
> That would seem to conflict with information from the URL below, from
> which I will paste a quote.
>
> http://java.sun.com/j2se/1.4.2/docs/guide/jdbc/getstart/mapping.html
>
> Methods added in the JDBC 2.0 core API make it possible for the driver
> to take a specified time zone into account when calculating a date,
> time, or timestamp. The time zone information is included in a
> java.util.Calendar object that is passed to new versions of the  
> methods
> for getting and setting Date, Time, and Timestamp values. When no time
> zone is specified, the driver uses the time zone of the virtual  
> machine
> running the application when it calculates a date, time, or timestamp.
>
>
>
>>>> Dave Cramer <pg@fastcrypt.com> 07/21/05 3:52 PM >>>
>>>>
>
> On 21-Jul-05, at 1:07 PM, Kevin Grittner wrote:
>
>
>> (1)  When storing a Timestamp object to a database column which is
>> defined as a timestamp with a time zone, what time zone should be
>> used?
>> Regardless of the choice, the value in the column must represent the
>> same moment as the original Timestamp object.  It seems clear that
>> some
>> methods allow you to specify a Calendar object for the sole  
>> purpose of
>> specifying the time zone, and that in the absence of that, the  
>> default
>> time zone of the JVM should be used.
>>
>>
> According to the JDBC API tutorial the time zone of the server
>
>
> ---------------------------(end of  
> broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faq
>
>




view thread (92+ messages)  latest in thread

Message-ID: <2B25D0C2-4C32-4641-91B7-48DAA498B9C9@fastcrypt.com>
Permalink:  ../2B25D0C2-4C32-4641-91B7-48DAA498B9C9@fastcrypt.com/
Also on:    postgresql.org/message-id/2B25D0C2-4C32-4641-91B7-48DAA498B9C9@fastcrypt.com

 · 

reply

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: pg@fastcrypt.com, Kevin.Grittner@wicourts.gov
  Subject: Re: Timestamp Conversion Woes Redux
  In-Reply-To: <2B25D0C2-4C32-4641-91B7-48DAA498B9C9@fastcrypt.com>
  References: <s2dfc8ca.027@gwmta.wicourts.gov> <2B25D0C2-4C32-4641-91B7-48DAA498B9C9@fastcrypt.com>

* 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