Re: scale parameter to setObject method - Mailing list pgsql-jdbc

From Bob Bruynooghe
Subject Re: scale parameter to setObject method
Date
Msg-id 57DA0FFB-58BC-4799-ADA0-10B9A7EFE91E@mac.com
Whole thread Raw
In response to Re: scale parameter to setObject method  (Kris Jurka <books@ejurka.com>)
List pgsql-jdbc
On 11 Sep 2008, at 18:36, Kris Jurka wrote:

>
>
> On Fri, 5 Sep 2008, Bob Bruynooghe wrote:
>
>> I am calling the method setObject(int parameterIndex, Object x, int
>> targetSqlType) with NUMERIC as the targetSqlType and a BigDecimal
>> value of -92233720368.54775 as x. I expected the value placed in
>> the database to have no fractional part. In fact the database
>> contains -92233720368.54775.
>
> I'm not sure why you expect no fraction here, the numeric type does
> support fractional parts.

Well, it is because the Javadoc for the method says the following:
     "This method is like the method setObject above, except that it
assumes a scale of zero."

The method that refers to is the version of setObject with 4
parameters and the Javadoc for that says
    "scale - for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC
types, this is the number of digits after the decimal point."

The implementation of the 3 parameter setObject  method in
AbstractJdbc2Statement is

public void setObject(int parameterIndex, Object x, int targetSqlType)
throws SQLException {
         setObject(parameterIndex, x, targetSqlType, 0);
}
which matches the "assume a scale of zero".

This is the first time I have looked at this method and I was
surprised that the specified behaviour was to set the scale to zero
for NUMERIC parameters. I have no idea how other JDBC drivers
implement the method.
>
>
>> I have also tried using the method setObject(int parameterIndex,
>> Object x, int targetSqlType, int scale) and setting the scale
>> explicitly. The value of scale is being ignored.
>
> Yes, this is a bug in the driver.
>
> Kris Jurka


regards
Bob Bruynooghe

pgsql-jdbc by date:

Previous
From: Andre Bialojahn
Date:
Subject: Re: German translation fixes
Next
From: "Michael Nacos"
Date:
Subject: pgBee - a Postgresql Bulk Updater in Java