X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 4E2BF32A4C4 for ; Fri, 15 Oct 2004 00:34:08 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 97996-08 for ; Thu, 14 Oct 2004 23:34:00 +0000 (GMT) Received: from cascavel.amazon.com.br (cascavel.amazon.com.br [200.241.240.57]) by svr1.postgresql.org (Postfix) with ESMTP id 4E37332A3C4 for ; Fri, 15 Oct 2004 00:34:01 +0100 (BST) Received: from localhost (localhost [127.0.0.1]) by cascavel.amazon.com.br (Amazon-Mail) with ESMTP id 13F822F2D4B for ; Thu, 14 Oct 2004 20:32:55 -0300 (BRT) Received: from cascavel.amazon.com.br ([127.0.0.1]) by localhost (cascavel [127.0.0.1:10024]) (amavisd-new) with ESMTP id 11096-02 for ; Thu, 14 Oct 2004 20:32:54 -0300 (BRT) Received: from [127.0.0.1] (201009182127.user.veloxzone.com.br [201.9.182.127]) by cascavel.amazon.com.br (Amazon-Mail) with ESMTP id 802A62F29CA for ; Thu, 14 Oct 2004 20:32:53 -0300 (BRT) Message-ID: <416F0CD1.8050202@amazon.com.br> Date: Thu, 14 Oct 2004 20:33:37 -0300 From: Jair da Silva Ferreira Jr User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: Re: problem with dates when using a java calendar object with References: <416DB991.3060809@amazon.com.br> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at Amazon Corporation X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/154 X-Sequence-Number: 11259 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 > >. > > >