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 2989D329F67 for ; Mon, 18 Oct 2004 13:57:31 +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 61430-05 for ; Mon, 18 Oct 2004 12:57:23 +0000 (GMT) Received: from cascavel.amazon.com.br (cascavel.amazon.com.br [200.241.240.57]) by svr1.postgresql.org (Postfix) with ESMTP id A9A31329EC4 for ; Mon, 18 Oct 2004 13:57:24 +0100 (BST) Received: from localhost (localhost [127.0.0.1]) by cascavel.amazon.com.br (Amazon-Mail) with ESMTP id 6BAF62F26C2; Mon, 18 Oct 2004 09:56:13 -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 27877-01; Mon, 18 Oct 2004 09:56:11 -0300 (BRT) Received: from [127.0.0.1] (201009181085.user.veloxzone.com.br [201.9.181.85]) by cascavel.amazon.com.br (Amazon-Mail) with ESMTP id 158DC2F2712; Mon, 18 Oct 2004 09:56:10 -0300 (BRT) Message-ID: <4173BD9C.1010908@amazon.com.br> Date: Mon, 18 Oct 2004 09:57:00 -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: pg@fastcrypt.com Cc: pgsql-jdbc@postgresql.org, schabios@logi-track.com Subject: Re: problem with dates when using a java calendar object with References: <416DB991.3060809@amazon.com.br> <20041014100201.761efae5@kingfisher.intern.logi-track.com> <416E9011.50908@amazon.com.br> <20041015121147.68987296@kingfisher.intern.logi-track.com> <41703CD7.3030608@amazon.com.br> <41704B97.1050707@fastcrypt.com> <41712DC0.1090307@amazon.com.br> <41713C87.7010604@fastcrypt.com> In-Reply-To: <41713C87.7010604@fastcrypt.com> Content-Type: multipart/mixed; boundary="------------090000020102000903000104" 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/189 X-Sequence-Number: 11294 This is a multi-part message in MIME format. --------------090000020102000903000104 Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit Dave Cramer wrote: > Jair, > > When using the newer drivers, did you use setDate( ) with the > appropriate calendar object ? Yes, I am passing the Calendar object to the setDate() method. > > If you have test code, can you send it ? Yes, I have test code. It is attached in this email. Am I doing something wrong in my test code? Thanks, Jair Jr > > Dave > > Jair da Silva Ferreira Jr wrote: > >> Hi Dave, >> Thanks for your reply. >> >> Dave Cramer wrote: >> >>> As Kris already pointed out you can use the calendar specified by >>> the user now; if you download the development driver. >> >> >> >> I have used the following drivers in my test program: >> pg72jdbc2.jar, pgdev.306.jdbc2.jar and pgdev.306.jdbc3.jar. All of >> them presented the problem but with different time errors. The test >> results are above. I am using a DateFormat to print dates. The >> DateFormat object is appropriately configured for my timezone and >> calendar. Any other ideas? :-) >> >> Using driver: pg72jdbc2.jar >> date (0) inserted: 16/10/04 00:00 >> date (1) inserted: 16/10/04 23:59 >> date (2) inserted: 16/10/04 08:00 >> date (3) inserted: 16/10/04 19:00 >> date (0) loaded: 15/10/04 17:00 >> date (1) loaded: 16/10/04 17:00 >> date (2) loaded: 15/10/04 17:00 >> date (3) loaded: 16/10/04 17:00 >> >> Using driver: pgdev.306.jdbc2.jar >> date (0) inserted: 16/10/04 00:00 >> date (1) inserted: 16/10/04 23:59 >> date (2) inserted: 16/10/04 08:00 >> date (3) inserted: 16/10/04 19:00 >> date (0) loaded: 15/10/04 10:00 >> date (1) loaded: 16/10/04 10:00 >> date (2) loaded: 15/10/04 10:00 >> date (3) loaded: 16/10/04 10:00 >> >> Using driver: pgdev.306.jdbc3.jar >> date (0) inserted: 16/10/04 00:00 >> date (1) inserted: 16/10/04 23:59 >> date (2) inserted: 16/10/04 08:00 >> date (3) inserted: 16/10/04 19:00 >> date (0) loaded: 15/10/04 10:00 >> date (1) loaded: 16/10/04 10:00 >> date (2) loaded: 15/10/04 10:00 >> date (3) loaded: 16/10/04 10:00 >> >> Thanks, >> Jair Jr >> >>> >>> Dave >>> >>> Jair da Silva Ferreira Jr wrote: >>> >>>> 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 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 >>>> >>>> >>>> ---------------------------(end of >>>> broadcast)--------------------------- >>>> TIP 2: you can get off all lists at once with the unregister command >>>> (send "unregister YourEmailAddressHere" to >>>> majordomo@postgresql.org) >>>> >>>> >>> >> >> >> >> ---------------------------(end of broadcast)--------------------------- >> TIP 9: the planner will ignore your desire to choose an index scan if >> your >> joining column's datatypes do not match >> >> > --------------090000020102000903000104 Content-Type: text/plain; name="JDBCTest2.java" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="JDBCTest2.java" import java.sql.*; import java.util.*; import java.text.*; public class JDBCTest2 { public static void execute(Connection c,List dates,GregorianCalendar cal,boolean useCalendarInJDBC)throws SQLException{ DateFormat df=new SimpleDateFormat(); df.setCalendar(cal); df.setTimeZone(cal.getTimeZone()); int j=0; PreparedStatement ps=c.prepareStatement("insert into date_test values (?)"); for(Iterator it=dates.iterator();it.hasNext();){ java.sql.Date d=(java.sql.Date)it.next(); if(useCalendarInJDBC){ ps.setDate(1,d,cal); } else{ ps.setDate(1,d); } ps.executeUpdate(); System.out.println("date ("+(j++)+") inserted: "+df.format(d)); } ps.close(); Statement s2=c.createStatement(); ResultSet rs=s2.executeQuery("select * from date_test "); List loadedDates=new ArrayList(); j=0; while(rs.next()){ java.sql.Date d; if(useCalendarInJDBC){ d=rs.getDate(1,cal); } else{ d=rs.getDate(1); } loadedDates.add(d); System.out.println("date ("+(j++)+") loaded: "+df.format(d)); } for(int i=0;i