Re: JDBC driver throws SQLException while parsing timestamp

From: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
To: adietrich(at)webantz(dot)com, pgsql-bugs(at)postgresql(dot)org
Subject: Re: JDBC driver throws SQLException while parsing timestamp
Date: 2001-01-26 20:10:02
Message-ID: 200101262010.PAA02071@candle.pha.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I think this is fixed in 7.1beta.

> Alexander Dietrich (adietrich(at)webantz(dot)com) reports a bug with a severity of 2
> The lower the number the more severe it is.
>
> Short Description
> JDBC driver throws SQLException while parsing timestamp
>
> Long Description
> Hi,
>
> there's a discrepancy between PreparedStatement.setTimestamp() and
> ResultSet.getTimestamp() related to a timestamp format that may or
> may not be valid (sorry I can't give a complete code sample):
> -----
> I do something like this to store the timestamp:
>
> Connection conn = ConnectionFactory.getConnection();
> PreparedStatement stmt = conn.prepareStatement(getInsertString());
> [...]
> stmt.setTimestamp(5, new Timestamp(System.currentTimeMillis()));
> stmt.executeUpdate();
> -----
> This is an example of what ends up in the database:
> type: timestamp, value: "2001-01-25 11:33:19.50+01"
> (Checked with psql)
> -----
> But when retrieving the data:
>
> [...]
> ResultSet rs = stmt.executeQuery(queryStr);
> Timestamp timestamp = rs.getTimestamp("CREATION_TIME");
>
> An SQLException is thrown:
>
> Bad Timestamp Format at 19 in 2001-01-25 11:33:19.50+01
>
> java.lang.Throwable()
> java.lang.Exception()
> java.sql.SQLException()
> org.postgresql.util.PSQLException(java.lang.String, java.lang.Object, java.lang.Object)
> java.sql.Timestamp org.postgresql.jdbc2.ResultSet.getTimestamp(int)
> java.sql.Timestamp org.postgresql.jdbc2.ResultSet.getTimestamp(java.lang.String)
> [...]
> -----
>
> Obviously the getTimestamp() method chokes on the millisecond field
> in the timestamp. A timestamp like "2001-01-25 11:33:19+01" does not
> pose a problem.
>
> My configuration is:
> Server:
> RedHat 7.0 (x86), 2.2.16-22
> postgresql-server-7.0.3-2
> postgresql-7.0.3-2
> postgresql-jdbc-7.0.3-2
>
> Client:
> JVM: 1.2.2 inside VisualAge 3.5 Patch 2
> JDBC driver: jdbc7.0-1.2.jar
>
> Regards,
> Alexander Dietrich
>
> Sample Code
>
>
> No file was uploaded with this report
>
>

--
Bruce Momjian | http://candle.pha.pa.us
pgman(at)candle(dot)pha(dot)pa(dot)us | (610) 853-3000
+ If your life is a hard drive, | 830 Blythe Avenue
+ Christ can be your backup. | Drexel Hill, Pennsylvania 19026

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2001-01-26 21:26:59 Re: select fails on indexed varchars.
Previous Message Paul M. Aoki 2001-01-26 19:12:44 Re: [JDBC] Re: no way in LargeObject API to detect short read?