Re: JDBC date problem

From: Michael Stephenson <mstephenson(at)tirin(dot)openworld(dot)co(dot)uk>
To: "Pgsql-Interfaces(at)Postgresql(dot) Org" <pgsql-interfaces(at)postgresql(dot)org>
Subject: Re: JDBC date problem
Date: 2001-01-10 09:42:00
Message-ID: Pine.LNX.4.30.0101100935480.1704-100000@tirin.openworld.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

> Any ideas? This is a real stumper and I need to find a solution asap! I'm
> using a JDBC driver I built from CVS no more than a month ago.

The results look to me like that in org.postgresql.jdbc2.ResultSet
'mm' and 'MM' have been confused (I know that this was the case in a patch
I submitted), try replacing getTimeStamp() with:

public Timestamp getTimestamp(int columnIndex) throws SQLException
{
String s = getString(columnIndex);
if(s==null)
return null;

SimpleDateFormat df = null;
if (s.length()>21 && s.indexOf('.') != -1) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSzzz");
} else if (s.length()>19 && s.indexOf('.') == -1) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:sszzz");
} else if (s.length()>19 && s.indexOf('.') != -1) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SS");
} else if (s.length()>10 && s.length()<=18) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
} else {
df = new SimpleDateFormat("yyyy-MM-dd");
}

try {
return new Timestamp(df.parse(s).getTime());
} catch(ParseException e) {
throw new PSQLException("postgresql.res.badtimestamp",new
Integer(e.getErrorOffset()),s);
}
}

Michael Stephenson

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Joseph 2001-01-10 11:53:10 RE: ReadOnly
Previous Message Cedar Cox 2001-01-10 09:36:49 Re: Please help with PostgreSQL