From: | David Brownlee <abs(at)formula1(dot)com> |
---|---|
To: | <pgsql-jdbc(at)postgresql(dot)org> |
Subject: | date problem with postgres JDBC 7.1 driver |
Date: | 2001-10-05 15:06:30 |
Message-ID: | Pine.NEB.4.33.0110051544100.22545-100000@odysseus.mono.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-jdbc |
(I'm not subscribed to the list, please cc directly in replies)
We have an application using the jdbc driver from postgres
7.0.x, compiled under java1. We have migrated the database
to 7.1.2, and would like to update the jdbc driver to match.
The application selects() a timestamp as a date, which
works fine under the earlier JDBC, and other databases such
as MS SQLserver, but fails with a NumberFormatException under
the new driver.
Can anyone confirm if this is correct JDBC behaviour (in which
case I have to persuade our developers to update their code :)
Sample code appended.
Thanks
--
David/absolute abs(at)formula1(dot)com
import java.math.*;
import java.sql.*;
import java.util.*;
/*
CREATE TABLE Race
( RaceId int NOT NULL,
RaceDate timestamp NOT NULL,
CONSTRAINT PK_Race PRIMARY KEY (RaceId)
);
INSERT INTO Race VALUES (195001, '1950-05-13');
Output after running with earlier class files:
Race Id = 195001
Race Date as Timestamp = 1950-05-13 00:00:00.0
Race Date as Date = 1950-05-13
Output after running with newest class files:
Race Id = 195001
Race Date as Timestamp = 1950-05-13 00:00:00.0
java.lang.NumberFormatException: 13 00:00:00+01
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.sql.Date.valueOf(Unknown Source)
at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:427)
at org.postgresql.jdbc2.ResultSet.getDate(ResultSet.java:665)
at Remote.main(Remote.java:33)
*/
public class Remote
{
public static void main(String args[])
{
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try
{
Class.forName("org.postgresql.Driver");
conn = DriverManager.getConnection("jdbc:postgresql://wopr:5432/f1archive", "tom", "");
ps = conn.prepareStatement("SELECT RaceId, RaceDate FROM Race WHERE RaceId = 195001;");
rs = ps.executeQuery();
while (rs.next())
{
System.out.println("Race Id = " + rs.getInt("RaceId"));
System.out.println("Race Date as Timestamp = " + rs.getTimestamp("RaceDate"));
System.out.println("Race Date as Date = " + rs.getDate("RaceDate"));
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if (rs != null)
rs.close();
if (ps != null)
ps.close();
if (conn != null)
conn.close();
}
catch(SQLException e) {}
}
}
}
From | Date | Subject | |
---|---|---|---|
Next Message | Gunnar Rønning | 2001-10-06 14:25:36 | Re: Serialize |
Previous Message | Dave Cramer | 2001-10-05 14:22:14 | Re: Serialize |