Skip site navigation (1) Skip section navigation (2)

JDBC setTimestamp/getTimestamp

From: Nissim <nissim(at)nksystems(dot)com>
To: pgsql-interfaces(at)hub(dot)org
Subject: JDBC setTimestamp/getTimestamp
Date: 2000-06-03 16:12:15
Message-ID: 39392E5F.8AF61D0E@nksystems.com (view raw or flat)
Thread:
Lists: pgsql-interfaces
Hi,

if you do 

Calendar cal = Calendar.getInstance();
cal.setTime( new java.util.Date() );
stmt.setTimeStamp( 1, new java.sql.Timestamp( cal.getTime().getTime() )
);

where param 1 is a column with datatype timestamp.

And then you do

rset.getTimeStamp( 1 );

to select the same column,

you get an exception, because the setTimeStamp did a toString() on the
java.sql.Timestamp, which returns "yyyy-mm-dd hh:mm:ss.fffffffff".  Then
the select statement will return something like this: "2000-06-03
11:47:47.85-04" and the getTimeStamp tries to shove thaat into a
SimpleDateFormat initialized with this: "yyyy-MM-dd HH:mm:sszzz".

Would the following be a bad way to fix this?

Check if the string with the date value contains "." and then use a
different format string.

I think it would probably be better if the server always returned
"yyyy-MM-dd HH:mm:ss.SSSzzz" regardless of whether milliseconds were
specified in the Insert/Update.

	-Nissim

Responses

pgsql-interfaces by date

Next:From: Billy G. AllieDate: 2000-06-04 05:40:47
Subject: PyGreSQL-3.0 bug + patch
Previous:From: Bruce MomjianDate: 2000-06-03 01:40:55
Subject: Re: Simple bug in JDBC interface

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group