JDBC bug in 7.1b4

From: "Rainer Mager" <rmager(at)vgkk(dot)com>
To: <pgsql-bugs(at)postgresql(dot)org>
Subject: JDBC bug in 7.1b4
Date: 2001-02-22 00:28:59
Message-ID: NEBBJBCAFMMNIHGDLFKGMEDADCAA.rmager@vgkk.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi all,

I already reported this directly to Peter Mount but since I have since
joined this list I thought I should make it a more wide-spread report.

The issue is that if you use getDate() on a field that is a timestamp type
then you will get an SQLException that wraps a NumberFormatException. While
this behavior is arguably correct, our main problem is that PG 7.0 did not
have this problem and I think it would be nice if 7.1 didn't break our old
code.
To that end, the following is as replacement to the getDate() method it
ResultSet and fixes the problem, at least for me. I think it is harmless to
provide the ability to get a date from a timestamp. If you do not agree to
add this to the JDBC driver please let me know ASAP so that I can begin
fixing our code in preparation for 7.1.

/**
* Get the value of a column in the given row as a java.sql.Date
* object. This handles both <code>Timestamp</code> and <code>
* Date</code> fields, truncating the time portion in the case of a
* Timestamp.
*
* @param columnIndex the first column is 1, the second is 2...
* @return the column value; null if SQL NULL
* @exception SQLException if a database access error occurs
*/
public java.sql.Date getDate( int columnIndex ) throws SQLException
{
String s = getString( columnIndex );
if( s == null )
return null;

java.sql.Date date = null;
try {
date = java.sql.Date.valueOf( s );
} catch( NumberFormatException e ) {
date = new java.sql.Date( getTimestamp( columnIndex ).getTime() );
}

return date;
}

Best regards,

--Rainer

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Dan Pereira 2001-02-22 00:30:08 makefile broken...
Previous Message Tom Lane 2001-02-22 00:16:33 Re: pg_dump 7.1beta4 misses a table