We are running a PostgreSQL server on a Debian 2.2 and we have problems with
the
mothod getTimestamp() of the ResultSet class;
we have find that if we insert a timestamp on a table, for example
'2000-10-09 12:21:34.321+01'
when we try to read that tuples using the JDBC driver we have an exception
on position 19.
The exception is caused by the milliseconds part of the timestamp!
We are using the following version of the data base
PostgreSQL 7.0.0 on i686-pc-linux-gnu, compiled by gcc 2.95.2
and we have tried to use the JDBC driver of the 7.1 release (downloading it
from CVS)
If we change the getTimestamp() methods of the
jdbc.postgresql.jdbc2.ResultSet
// Original code
public Timestamp getTimestamp(int columnIndex) throws SQLException
{
String s = getString(columnIndex);
if(s==null)
return null;
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzz");
try {
return new Timestamp(df.parse(s).getTime());
} catch(ParseException e) {
throw new PSQLException("postgresql.res.badtimestamp",new
Integer(e.getErrorOffset()),s);
}
}
with the following code
// New code
public Timestamp getTimestamp(int columnIndex) throws SQLException
{
String s = rs.getString(columnIndex);
if (s==null) return;
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz");
try {
return new Timestamp(df.parse(s).getTime());
} catch(ParseException e1) {
df=new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzz");
try {
return new Timestamp(df.parse(s).getTime());
} catch(ParseException e2) {
throw new PSQLException("postgresql.res.badtimestamp",new
Integer(e2.getErrorOffset()),s);
}
}
}
we have no exceptions from the JDBC driver!
(but why is a new SimpleDateFormat created every time something call this
methods? if we
create this object when the ResultSet is created we can avoid to create a
new
SimpleDateFormat every time the getTimestamp methods is called)
-Massimiliano Giorgi
Excuse me for my bad English.