X-Original-To: pgsql-jdbc@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id AD53F475425 for ; Sat, 8 Feb 2003 10:43:17 -0500 (EST) Received: from www14.your-server.de (www14.your-server.de [213.133.104.14]) by postgresql.org (Postfix) with SMTP id A09264753A1 for ; Sat, 8 Feb 2003 10:43:16 -0500 (EST) Received: (qmail 20927 invoked from network); 8 Feb 2003 15:43:10 -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; 8 Feb 2003 15:43:10 -0000 Received: from thiesen.com (th-serv1.thiesen.de [192.168.1.2]) by kontor.thiesen.de (8.12.3/8.12.3/SuSE Linux 0.6) with SMTP id h18Fgtg3025749 for ; Sat, 8 Feb 2003 16:42:55 +0100 Date: Sat, 8 Feb 2003 15:42:55 -0000 To: pgsql-jdbc@postgresql.org Subject: Re: Timestamp problems From: Peter Katzmann X-Mailer: twiggi 1.10.3 Reply-To: pet@thiesen.com Message-ID: <20030208164255.1ixbasveee4g0@.thiesen.com> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/208 X-Sequence-Number: 6379 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= will mapped to timestamp. But anyway, why is the timestamp manipulated. Didn't i understand it right that the timezone offset to gmt has to be adde= d at the end, and here it should be +1 one and not +0 peter Barry Lind schrieb: > Peter, > > I looked at the sample program you sent (thanks for the test program, it > makes it much easier to understand). From what I can tell the driver is > working correctly. > > The data type of the column datum that you create is 'date'. Since a > 'date' does not store any time information the rest of the behavior you > see is related to this fact. > > So why are you using setTimestamp/getTimestamp when the data type is > date? You should be using setDate/getDate. > > If I either change the data type to 'timestamp' in your program, or use > getDate/setDate with the 'date' data type everything works as I would > expect. > > The fact that you are mixing dates and timestamps I think is causing > your problems. However I believe the driver is functioning correctly > givin what your code is actually doing. > > thanks, > --Barry > > Peter Katzmann wrote: > > Hello Attached is the example with the same error and here is a small > > database log: > > 2003-02-07 14:32:32 [17354] LOG: connection received: > > host=3D192.168.2.11 port=3D33900 > > 2003-02-07 14:32:32 [17354] LOG: connection authorized: user=3Dpostgr= es > > database=3Dachievo > > 2003-02-07 14:32:32 [17354] LOG: query: set datestyle to 'ISO'; select > > version(), case when pg_encoding_to_char(1) =3D 'SQL_ASCII' then 'UNKNO= WN' > > else getdatabaseencoding() end; > > 2003-02-07 14:32:32 [17354] LOG: query: create temp table tmp ( datum > > date, idx int) > > 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp > > Values('2003-02-07 13:32:31.668000000+00', 0) > > 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp > > Values('2003-02-07 13:32:31.913000000+00', 1) > > 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp > > Values('2003-02-07 13:32:31.916000000+00', 2) > > 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp > > Values('2003-02-07 13:32:31.919000000+00', 3) > > 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp > > Values('2003-02-07 13:32:31.921000000+00', 4) > > 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp > > Values('2003-02-07 13:32:31.923000000+00', 5) > > 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp > > Values('2003-02-07 13:32:31.926000000+00', 6) > > 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp > > Values('2003-02-07 13:32:31.928000000+00', 7) > > 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp > > Values('2003-02-07 13:32:31.939000000+00', 8) > > 2003-02-07 14:32:32 [17354] LOG: query: insert into tmp > > 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 > > 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 > > 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 > > 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 > > 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 > > 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 > > 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 > > 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 > > 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 > > 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 > > 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? > >> Specifically have you tried the latest 7.3 build from > >> jdbc.postgresql.org? There were some recent bug fixes in this area > >> that I think may fix your problem. > >> > >> If the current code still has this problem, can you submit a test 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 > >>> generated for > >>> the query has a modified date. The date is something original: > >>> > >>> > >>> insert into hours ( entrydate, activitydate, remark, time, userid, > >>> checked, > >>> phaseid, activityid, zkub, id ) values '2003-02-06 > >>> 11:11:29.338000000+00', > >>> '2003-02-06 11:11:29.338000000+00', '=F6f=F6lsdajkl=F6', 120, 'pk1057= ', > >>> 'f', null, > >>> null, null, 12747 ) > >>> > >>> > >>> And this will be aftter the data was read back, the checked flag > >>> changed and > >>> wrote back > >>> > >>> update hours set entrydate =3D '2003-02-05 23:00:00.000000000+00', > >>> activitydate > >>> =3D '2003-02-05 23:00:00.000000000+00', remark =3D '=F6f=F6lsdajkl=F6= ', time =3D > >>> 120, > >>> userid =3D 'pk1057', checked =3D 't', phaseid =3D 5, activityid =3D 3= , zkub =3D > >>> ' ' > >>> where id =3D 12747 > >>> > >>> First occured the problem with postgres 7.2 so i updated to a current > >>> version, > >>> but no go either. > >>> > >>> > >>> peter > >>> > >>> > >>> > >>> ---------------------------(end of 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 dbConnect("jdbc:postgresql://kontor.thiesen.de:5432/achievo?charSet=3DISO-8= 859-15", "postgres", "postgres"); > > Statement state =3D dbConnection.createStatement(); > > state.execute("create temp table tmp ( datum date, idx int)"); > > PreparedStatement st1 =3D dbConnection.prepareStatement("insert i= nto tmp Values(?, ?)"); > > PreparedStatement st2 =3D dbConnection.prepareStatement("update t= mp set datum=3D? where idx=3D?"); > > > > for (int i =3D 0; i < 10; i++) { > > st1.setInt(2, i); > > st1.setTimestamp(1,new Timestamp(new 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, "DriverManager.getCon= nection() "+dbURL+" "+dbUser+" ********"); > > System.out.println( "DriverManager.getConnection() "+dbURL+" "+dbUs= er+" ********"); > > try { > > this.dbConnection =3D DriverManager.getConnection(dbURL, dbUser, = dbPasswd); > > } catch (SQLException se) { > > se.printStackTrace(); > > } > > > > try { > > DatabaseMetaData dmd =3D dbConnection.getMetaData(); > > String dbi =3D new String(); > > > > dbi =3D dbi.concat("--- database: "+dmd.getDatabaseProductName()+"\n"); > > dbi =3D dbi.concat("--- databse version: "+dmd.getDatabaseProductVersion()+"\n"); > > dbi =3D dbi.concat("--- JDBC driver name: "+dmd.getDriverName(= )+"\n"); > > dbi =3D dbi.concat("--- JDBC driver version: "+dmd.getDriverVersi= on()); > > //getMainSession().getDebug().message(this, "Database Info:\n"+db= i); > > System.out.println( "Database Info:\n"+dbi); > > } catch (SQLException se) { > > se.printStackTrace(); > > } > > > > } > > > > } > > > > > ---------------------------(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 > > -- Peter Katzmann