pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jair da Silva Ferreira Jr <j2@amazon.com.br>
To: pgsql-jdbc@postgresql.org
Subject: Re: problem with dates when using a java calendar object with
Date: Thu, 14 Oct 2004 20:33:37 -0300
Message-ID: <416F0CD1.8050202@amazon.com.br> (raw)
In-Reply-To: <Pine.BSO.4.56.0410140656260.19030@leary.csoft.net>
References: <416DB991.3060809@amazon.com.br>
	<Pine.BSO.4.56.0410140656260.19030@leary.csoft.net>

Hi Kris,

Kris Jurka wrote:

>On Wed, 13 Oct 2004, Jair da Silva Ferreira Jr wrote:
>
>  
>
>>I don't care about the time (hour, minute and second) 
>>difference as this is a SQL DATE type. The problem is that the days in 
>>these dates are different.
>>    
>>
>
>There are a number of problems going on here:
>
>First the JDBC driver didn't support using an alternate Calendar until
>very recently.  This functionality is only in the 8.0 series.
>  
>
    If the Calendar is not fully supported, in what timezone should my
dates be so that this problem does not happen? UTC? The default JVM
timezone?

>Second it doesn't make sense to store a timezone with a date alone.  You 
>need time information as well, so you've selected the wrong pg datatype 
>"date" and should probably be using "timestamp with time zone".
>  
>
    I am not trying to store the timezone in the database. I am just
trying to tell the jdbc driver that the date I am inserting or selecting
is in the specified timezone.

>Finally the javadoc says
>
>	To conform with the definition of SQL DATE, the millisecond values
>	wrapped by a java.sql.Date instance must be 'normalized' by
>	setting the hours, minutes, seconds, and milliseconds to zero in
>	the particular time zone with which the instance is associated.
>
>I believe this means your whole setTimeInDate method is not legal.
>  
>
    The setTimeInDate method is exactly trying to verify if the driver
is normalizing the date correctly. The algorithm is to set a time in the
date, insert it into the database and select it back hoping that the
driver sets the hours, minutes, seconds, and milliseconds to 0. But,
unfortunately, they are not 0, and, sometimes even the day of the date
is wrong. This is exactly the problem I'm trying to explain.

    I analysed the AbstractJdbc2Statement.java and
AbstractJdbc2ResultSet.java source code and noticed that you transform
the date in a String and them insert it into the database. Maybe the
problem is how the String is being generated. I think the best solution
is to use a java.text.DateFormat object with the calendar specified by
the user set on it. This DateFormat object could be used to both insert
and select the date value from the database because it has a
format(Date) and parse(Date) method. What do you think?

Thanks,
Jair

>Kris Jurka
>
>.
>
>  
>








view thread (10+ messages)  latest in thread

Message-ID: <416F0CD1.8050202@amazon.com.br>
Permalink:  ../416F0CD1.8050202@amazon.com.br/
Also on:    postgresql.org/message-id/416F0CD1.8050202@amazon.com.br

 · 

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: j2@amazon.com.br
  Subject: Re: problem with dates when using a java calendar object with
  In-Reply-To: <416F0CD1.8050202@amazon.com.br>
  References: <416DB991.3060809@amazon.com.br> <Pine.BSO.4.56.0410140656260.19030@leary.csoft.net> <416F0CD1.8050202@amazon.com.br>

* 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