X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id DA15B9DC838 for ; Mon, 16 Jan 2006 18:37:00 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 61591-02 for ; Mon, 16 Jan 2006 18:37:01 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [131.203.101.226]) by postgresql.org (Postfix) with ESMTP id 9BB049DC875 for ; Mon, 16 Jan 2006 18:36:56 -0400 (AST) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=[192.168.0.20]) by yass.opencloud.co.nz with asmtp (TLS-1.0:DHE_RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1Eycy7-0002A5-16; Tue, 17 Jan 2006 11:36:55 +1300 Message-ID: <43CC2006.9010000@opencloud.com> Date: Tue, 17 Jan 2006 11:36:54 +1300 From: Oliver Jowett User-Agent: Mozilla Thunderbird 1.0.7 (X11/20051009) X-Accept-Language: en-us, en MIME-Version: 1.0 To: dbadmin@nqadmin.com CC: pgsql-jdbc@postgresql.org Subject: Re: getDate after call to updateDate References: <4307C0C5.607@opencloud.com> <4309E8F5.5000507@nqadmin.com> <43CC1A76.1050402@nqadmin.com> In-Reply-To: <43CC1A76.1050402@nqadmin.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.11 required=5 tests=[AWL=0.110] X-Spam-Score: 0.11 X-Spam-Level: X-Archive-Number: 200601/77 X-Sequence-Number: 14528 Prasanth wrote: > But when I use the latest 8.1-404 or even 8.2dev jdbc3 drivers I am > observing a strange result. > > When I update a date in the resultset (say with 12/31/2005) and then > call getDate it returns a date which is one day behind the value I have > set (returns 12/30/2005). > But it updates the database with the right date (12/31/2005). If I re > fetch the same row then I can see the right value. I couldn't reproduce this with your testcase. Possibly the effect you're seeing is because you're not creating a strictly correct Date object: > Calendar c = Calendar.getInstance(); This gives you a Calendar for the current system time. > c.set(Calendar.MONTH, 1); > c.set(Calendar.DATE, 2); > c.set(Calendar.YEAR, 2005); This resets the date to 2005/02/01, but leaves the time portion unchanged. > Date d = new Date(c.getTimeInMillis()); This creates a java.sql.Date object that has a non-zero hour/minute/second, which strictly speaking you're not meant to have. The javadoc for java.sql.Date 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. Can you try a modified testcase that resets hours/minutes/seconds/milliseconds on the calendar before getting the millisecond value? I'm not quite sure why this would cause the problem you're seeing, though.. One other thing to try is to print the before/after values of d.getTime(), which gives more exact information than Date.toString() does. Also: what are the default timezones for your JVM and server? -O