X-Original-To: pgsql-jdbc@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 5374D474E5C for ; Mon, 10 Feb 2003 02:33:25 -0500 (EST) Received: from www14.your-server.de (www14.your-server.de [213.133.104.14]) by postgresql.org (Postfix) with SMTP id 31384474E53 for ; Mon, 10 Feb 2003 02:33:24 -0500 (EST) Received: (qmail 9828 invoked from network); 10 Feb 2003 07:33:19 -0000 Received: from port-14-41.gilat.ip.tiscali.net (HELO kontor.thiesen.de) (213.200.121.41) by www14.your-server.de with SMTP; 10 Feb 2003 07:33:19 -0000 Received: from thiesen.com (Pet.Thiesen.de [192.168.2.11]) by kontor.thiesen.de (8.12.3/8.12.3/SuSE Linux 0.6) with ESMTP id h1A7X5g3005894; Mon, 10 Feb 2003 08:33:05 +0100 Message-ID: <3E4755B2.1010405@thiesen.com> Date: Mon, 10 Feb 2003 08:33:06 +0100 From: Peter Katzmann Organization: thiesen Hardware & Software design GmbH User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.3b) Gecko/20030124 X-Accept-Language: de-DE, en MIME-Version: 1.0 To: Barry Lind Cc: pgsql-jdbc@postgresql.org Subject: Re: Timestamp problems References: <3E4266AC.4060907@thiesen.com> <3E429520.904@xythos.com> <3E43B5DC.60901@thiesen.com> <3E440D85.6040201@xythos.com> In-Reply-To: <3E440D85.6040201@xythos.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/177 X-Sequence-Number: 6348 Barry, the problem is that hibernate does this mapping. I have the data stored as date and wan't to get the Calendar type, this one= =20 will mapped to timestamp. For my understanding it should be no problem to convert a date to timestamp= =20 and back. The date should always be the same, shouldn't it ? Both represent a Calendar Date. peter Barry Lind wrote: > Peter, >=20 > I looked at the sample program you sent (thanks for the test program, it= =20 > makes it much easier to understand). From what I can tell the driver is= =20 > working correctly. >=20 > The data type of the column datum that you create is 'date'. Since a=20 > 'date' does not store any time information the rest of the behavior you= =20 > see is related to this fact. >=20 > So why are you using setTimestamp/getTimestamp when the data type is=20 > date? You should be using setDate/getDate. >=20 > If I either change the data type to 'timestamp' in your program, or use= =20 > getDate/setDate with the 'date' data type everything works as I would=20 > expect. >=20 > The fact that you are mixing dates and timestamps I think is causing=20 > your problems. However I believe the driver is functioning correctly=20 > givin what your code is actually doing. >=20 > thanks, > --Barry >=20 > Peter Katzmann wrote: >=20 >> Hello Attached is the example with the same error and here is a small=20 >> database log: >> 2003-02-07 14:32:32 [17354] LOG: connection received:=20 >> host=3D192.168.2.11 port=3D33900 >> 2003-02-07 14:32:32 [17354] LOG: connection authorized:=20 >> user=3Dpostgres database=3Dachievo >> 2003-02-07 14:32:32 [17354] LOG: query: set datestyle to 'ISO';=20 >> select version(), case when pg_encoding_to_char(1) =3D 'SQL_ASCII' then= =20 >> 'UNKNOWN' else getdatabaseencoding() end; >> 2003-02-07 14:32:32 [17354] LOG: query: create temp table tmp (=20 >> datum date, idx int) >> 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp=20 >> Values('2003-02-07 13:32:31.668000000+00', 0) >> 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp=20 >> Values('2003-02-07 13:32:31.913000000+00', 1) >> 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp=20 >> Values('2003-02-07 13:32:31.916000000+00', 2) >> 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp=20 >> Values('2003-02-07 13:32:31.919000000+00', 3) >> 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp=20 >> Values('2003-02-07 13:32:31.921000000+00', 4) >> 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp=20 >> Values('2003-02-07 13:32:31.923000000+00', 5) >> 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp=20 >> Values('2003-02-07 13:32:31.926000000+00', 6) >> 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp=20 >> Values('2003-02-07 13:32:31.928000000+00', 7) >> 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp=20 >> Values('2003-02-07 13:32:31.939000000+00', 8) >> 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp=20 >> Values('2003-02-07 13:32:31.941000000+00', 9) >> 2003-02-07 14:32:32 [17354] LOG: query: select * from tmp >> 2003-02-07 14:32:32 [17354] LOG: query: update tmp set=20 >> datum=3D'2003-02-06 23:00:00.000000000+00' where idx=3D0 >> 2003-02-07 14:32:32 [17354] LOG: query: update tmp set=20 >> datum=3D'2003-02-06 23:00:00.000000000+00' where idx=3D1 >> 2003-02-07 14:32:32 [17354] LOG: query: update tmp set=20 >> datum=3D'2003-02-06 23:00:00.000000000+00' where idx=3D2 >> 2003-02-07 14:32:32 [17354] LOG: query: update tmp set=20 >> datum=3D'2003-02-06 23:00:00.000000000+00' where idx=3D3 >> 2003-02-07 14:32:32 [17354] LOG: query: update tmp set=20 >> datum=3D'2003-02-06 23:00:00.000000000+00' where idx=3D4 >> 2003-02-07 14:32:32 [17354] LOG: query: update tmp set=20 >> datum=3D'2003-02-06 23:00:00.000000000+00' where idx=3D5 >> 2003-02-07 14:32:32 [17354] LOG: query: update tmp set=20 >> datum=3D'2003-02-06 23:00:00.000000000+00' where idx=3D6 >> 2003-02-07 14:32:32 [17354] LOG: query: update tmp set=20 >> datum=3D'2003-02-06 23:00:00.000000000+00' where idx=3D7 >> 2003-02-07 14:32:32 [17354] LOG: query: update tmp set=20 >> datum=3D'2003-02-06 23:00:00.000000000+00' where idx=3D8 >> 2003-02-07 14:32:32 [17354] LOG: query: update tmp set=20 >> datum=3D'2003-02-06 23:00:00.000000000+00' where idx=3D9 >> >> >> Barry Lind wrote: >> >>> Peter, >>> >>> When you say you tried with the current version what do you mean?=20 >>> Specifically have you tried the latest 7.3 build from=20 >>> jdbc.postgresql.org? There were some recent bug fixes in this area=20 >>> that I think may fix your problem. >>> >>> If the current code still has this problem, can you submit a test=20 >>> case that we can compile and run that demonstrates the problem? >>> >>> thanks, >>> --Barry >>> >>> >>> Peter Katzmann wrote: >>> >>>> High, >>>> i' currently working with hibernate. They represent Calendar types as >>>> timestamps. During prepareStatement and setTimestamp the data=20 >>>> generated for >>>> the query has a modified date. The date is something original: >>>> >>>> >>>> insert into hours ( entrydate, activitydate, remark, time, userid,=20 >>>> checked, >>>> phaseid, activityid, zkub, id ) values '2003-02-06=20 >>>> 11:11:29.338000000+00', >>>> '2003-02-06 11:11:29.338000000+00', '=F6f=F6lsdajkl=F6', 120, 'pk1057'= ,=20 >>>> 'f', null, >>>> null, null, 12747 ) >>>> >>>> >>>> And this will be aftter the data was read back, the checked flag=20 >>>> changed and >>>> wrote back >>>> >>>> update hours set entrydate =3D '2003-02-05 23:00:00.000000000+00',=20 >>>> activitydate >>>> =3D '2003-02-05 23:00:00.000000000+00', remark =3D '=F6f=F6lsdajkl=F6'= , time =3D=20 >>>> 120, >>>> userid =3D 'pk1057', checked =3D 't', phaseid =3D 5, activityid =3D 3,= zkub=20 >>>> =3D ' ' >>>> where id =3D 12747 >>>> >>>> First occured the problem with postgres 7.2 so i updated to a=20 >>>> current version, >>>> but no go either. >>>> >>>> >>>> peter >>>> >>>> >>>> >>>> ---------------------------(end of=20 >>>> broadcast)--------------------------- >>>> TIP 5: Have you checked our extensive FAQ? >>>> >>>> http://www.postgresql.org/users-lounge/docs/faq.html >>>> >>>> >>> >>> >>> >>> >>> ---------------------------(end of broadcast)--------------------------- >>> TIP 2: you can get off all lists at once with the unregister command >>> (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) >>> >> >> >> >> ------------------------------------------------------------------------ >> >> /* >> * TryOut.java >> * >> * Created on 7. Februar 2003, 13:36 >> */ >> >> import java.sql.*; >> >> >> /** >> * >> * @author root >> */ >> public class TryOut { >> private java.sql.Connection dbConnection =3D null; >> /** Die URL zur Datenbank */ >> private String dbURL =3D null; >> /** Der Datenbank-Banutzer */ >> private String dbUser =3D null; >> /** Das Password des Datenbank-Benutzers */ >> private String dbPasswd =3D null; >> /*********************** >> * simple table of the form >> * >> * >> * /** Creates a new instance of TryOut */ >> public TryOut() { >> } >> /** >> * @param args the command line arguments >> */ >> public static void main(String[] args) { >> TryOut tr =3D new TryOut(); >> tr.doIt(); >> } >> private void doIt() { >> try { >> Class.forName("org.postgresql.Driver"); >>=20=20=20=20=20=20=20 >> dbConnect("jdbc:postgresql://kontor.thiesen.de:5432/achievo?charSet=3DIS= O-8859-15",=20 >> "postgres", "postgres"); >> Statement state =3D dbConnection.createStatement(); >> state.execute("create temp table tmp ( datum date, idx int)"); >> PreparedStatement st1 =3D dbConnection.prepareStatement("insert=20 >> into tmp Values(?, ?)"); >> PreparedStatement st2 =3D dbConnection.prepareStatement("update=20 >> tmp set datum=3D? where idx=3D?"); >> for (int i =3D 0; i < 10; i++) { >> st1.setInt(2, i); >> st1.setTimestamp(1,new Timestamp(new=20 >> java.util.Date().getTime())); >> st1.execute(); >> } >> ResultSet rs =3D state.executeQuery("select * from tmp"); >> for (int i =3D 0; i < 10; i++) { >> rs.absolute(i+1); >> st2.setTimestamp(1, new Timestamp(rs.getDate(1).getTime())); >> st2.setInt(2, i); >> st2.execute(); >> } >> dbConnection.close(); >> } catch (Exception e) { >> e.printStackTrace(); >> } >> } >> /* Oeffnet die Datenbankverbindung >> * >> * @param dbUrl die JDBC-RessourcenURL >> * @param dbUser dbUser >> * @param dbPasswd >> * >> * @exception SQLException noch Fragen? >> */ >> public void dbConnect(String dbURL, String dbUsr, String dbPwd) { >> this.dbURL =3D dbURL; >> this.dbUser =3D dbUsr; >> this.dbPasswd =3D dbPwd; >> dbConnect(); >> } >> /** >> * Oeffnet die Datenbankverbindung >> * >> * @param dbUrl die JDBC-RessourcenURL >> * @param dbUser dbUser >> * @param dbPasswd >> * >> * @exception SQLException noch Fragen? >> */ >> private void dbConnect() { >> /* Verbindung zur Datenbank aufbauen */ >> // getMainSession().getDebug().message(this,=20 >> "DriverManager.getConnection() "+dbURL+" "+dbUser+" ********"); >> System.out.println( "DriverManager.getConnection() "+dbURL+"=20 >> "+dbUser+" ********"); >> try { >> this.dbConnection =3D DriverManager.getConnection(dbURL, dbUser,= =20 >> dbPasswd); >> } catch (SQLException se) { >> se.printStackTrace(); >> } >> try { >> DatabaseMetaData dmd =3D dbConnection.getMetaData(); >> String dbi =3D new String(); >> dbi =3D dbi.concat("--- database:=20 >> "+dmd.getDatabaseProductName()+"\n"); >> dbi =3D dbi.concat("--- databse version:=20 >> "+dmd.getDatabaseProductVersion()+"\n"); >> dbi =3D dbi.concat("--- JDBC driver name:=20 >> "+dmd.getDriverName()+"\n"); >> dbi =3D dbi.concat("--- JDBC driver version:=20 >> "+dmd.getDriverVersion()); >> //getMainSession().getDebug().message(this, "Database=20 >> Info:\n"+dbi); >> System.out.println( "Database Info:\n"+dbi); >> } catch (SQLException se) { >> se.printStackTrace(); >> } >> } >> } >=20 >=20 >=20 >=20 >=20 > ---------------------------(end of broadcast)--------------------------- > TIP 3: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly >=20 --=20 Thiesen hardware & software GmbH | P. Katzmann Bereichsleiter SW Entwicklung | p.katzmann@thiesen.com Im Tiegel 9 | www.thiesen.com 36367 Wartenberg | tel. +49 (0) 6641 979 140 fax +49 (0) 6641 979 299