Re: problem with dates when using a java calendar object with - Mailing list pgsql-jdbc

From Jair da Silva Ferreira Jr
Subject Re: problem with dates when using a java calendar object with
Date
Msg-id 41703CD7.3030608@amazon.com.br
Whole thread Raw
In response to problem with dates when using a java calendar object with a non-default timezone  (Jair da Silva Ferreira Jr <j2@amazon.com.br>)
Responses Re: problem with dates when using a java calendar object with  (Dave Cramer <pg@fastcrypt.com>)
List pgsql-jdbc
Hi Markus,
    Thank you very much for your reply.

Markus Schaber wrote:

>Hi, Jair,
>
>On Thu, 14 Oct 2004 11:41:21 -0300
>Jair da Silva Ferreira Jr <j2@amazon.com.br> wrote:
>
>
>
>>My test table definition is: create table date_test (d date)
>>As you can see it is a date type, so there's no time zone information on it.
>>Do you think that the date not having time zone information is the
>>source of the problem? If yes, what time zone should I use so that dates
>>are correctly inserted and selected? UTC time zone? The default JVM
>>timezone?
>>
>>
>
>It is possible that this is the source of your problem.
>
>Table columns with time zone always remember the time zone of the dates
>stored, while the table columns without time zone convert your date to
>UTC and forget the original time zone.
>
>This had to be changed at postgres level. Just test whether manually
>inserting dates (e. G. via psql) and then re-reading works.
>
>
    I inserted dates via pgsql and selected them via Java and the
problem remains. I keep getting wrong days in my date. I think the JDBC
driver is somehow considering the current jvm timezone to calculate
dates. I think this is wrong because I am providing a user-defined
Calendar exactly not to use the jvm default.
    I analysed the AbstractJdbc2Statement.java and
AbstractJdbc2ResultSet.java source code and I noticed that the driver
transforms the date in a String and them inserts 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 Jr


pgsql-jdbc by date:

Previous
From: Oliver Jowett
Date:
Subject: Re: A solution to the SSL customizing problem
Next
From: Dave Cramer
Date:
Subject: Re: problem with dates when using a java calendar object with