X-Original-To: pgsql-jdbc@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id EE48B475A45 for ; Mon, 10 Feb 2003 12:23:39 -0500 (EST) Received: from mail.xythos.com (ip-216-36-77-241.dsl.sjc.megapath.net [216.36.77.241]) by postgresql.org (Postfix) with ESMTP id D6A8D475A3F for ; Mon, 10 Feb 2003 12:23:37 -0500 (EST) Received: from ravms by mail.xythos.com with mail-ok (Exim 3.36 #3) id 18iHeg-0006DG-00; Mon, 10 Feb 2003 17:23:42 +0000 Received: from ip-216-36-77-241.dsl.sjc.megapath.net ([216.36.77.241] helo=xythos.com) by mail.xythos.com with asmtp (Exim 3.36 #3) id 18iHeg-0006D5-00; Mon, 10 Feb 2003 17:23:42 +0000 Message-ID: <3E47DBC7.1010609@xythos.com> Date: Mon, 10 Feb 2003 09:05:11 -0800 From: Barry Lind User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021130 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Peter Katzmann 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> <3E4755B2.1010405@thiesen.com> In-Reply-To: <3E4755B2.1010405@thiesen.com> Content-Type: text/plain; charset=ISO-8859-15; format=flowed X-Envelope-To: p.katzmann@thiesen.com, pgsql-jdbc@postgresql.org Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/184 X-Sequence-Number: 6355 Peter, Converting from a date to a timestamp and back can be difficult. The=20 reason is timezones. java.sql.Date does not have a concept of timezone,=20 but java.sql.Timestamp does. The timezone offset can easily move the=20 date portion of a timestamp to a different date. As I said in my mail note, I believe the jdbc driver is behaving=20 according to spec. I certainly could be wrong however. I need you to=20 explain exactly what behavior you think is not compliant with the spec=20 and why, along with providing examples as appropriate. thanks, --Barry Peter Katzmann wrote: > 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= =20 > one will mapped to timestamp. > For my understanding it should be no problem to convert a date to=20 > timestamp and back. The date should always be the same, shouldn't it ? > Both represent a Calendar Date. >=20 > peter >=20 > Barry Lind wrote: >=20 >> Peter, >> >> I looked at the sample program you sent (thanks for the test program,=20 >> it makes it much easier to understand). From what I can tell the=20 >> driver is working correctly. >> >> 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=20 >> you see is related to this fact. >> >> So why are you using setTimestamp/getTimestamp when the data type is=20 >> date? You should be using setDate/getDate. >> >> If I either change the data type to 'timestamp' in your program, or=20 >> use getDate/setDate with the 'date' data type everything works as I=20 >> would expect. >> >> 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. >> >> thanks, >> --Barry >> >> Peter Katzmann wrote: >> >>> 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=20 >>>>> =3D 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=20 >>>> 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=3DI= SO-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(); >>> } >>> } >>> } >> >> >> >> >> >> >> ---------------------------(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