Re: bug report: preparedStatement.setObject(indx, "2004-August-15", java.sql.Types.DATE) generates number format exception

From: Kris Jurka <books(at)ejurka(dot)com>
To: Floyd Shackelford <shackman(at)fwshackelford(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: bug report: preparedStatement.setObject(indx, "2004-August-15", java.sql.Types.DATE) generates number format exception
Date: 2007-02-14 19:36:15
Message-ID: Pine.BSO.4.64.0702141433300.24142@leary.csoft.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

On Wed, 14 Feb 2007, Floyd Shackelford wrote:

> the following generates a number format exception:
> preparedStatement.setObject(indx,"2004-August-15",java.sql.Types.DATE)
>
> the following works:
> preparedStatement.setObject(indx,"2004-08-15",java.sql.Types.DATE)
>
> i prefer to use the former.
>

I'm not sure that's actually a bug as there are many, many possible date
formats and the JDBC spec doesn't specify what conversions must be
supplied. Do you use this same code on other databases?

Using a SimpleDateFormat object to convert from String to Date yourself is
the most portable and guaranteed correct method.

Kris Jurka

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jeffrey Cox 2007-02-14 19:40:01 Re: getProcedureColumns
Previous Message Chris Gamache 2007-02-14 19:29:06 Re: stringtype=unspecified problem