Thread: any issues with SQL arrays of decimals?

any issues with SQL arrays of decimals?

From
Richard Welty
Date:
i have a bunch of code that was working with integer arrays which i just
converted to work with decimals.

the array is in the database correctly. from psql, target_percentages is:

 {0.08,0.08,0.09,0.08,0.08,0.09,0.08,0.08,0.09,0.08,0.08,0.09}

from my java code:

  target_percentages = (BigDecimal[]) result.getArray( "target_percentages").getArray();

which is producing the following exception:

SQLException: Bad BigDecimal 0.08

this code worked when it was an array of ints, and 0.08 is hardly a bad
BigDecimal.

this is postgresql 7.2.1-5 from an rpm on redhat 7.3, using the pgjdbc2.jar
driver from october of  last year. the jdk is 1.4.1_01

any suggestions?

thanks,
  richard
--
Richard Welty                                         rwelty@averillpark.net
Averill Park Networking                                         518-573-7592
              Unix, Linux, IP Network Engineering, Security

Re: any issues with SQL arrays of decimals?

From
Richard Welty
Date:
following myself up:

On Sat, 22 Feb 2003 15:00:21 -0500 (EST) Richard Welty <rwelty@averillpark.net> wrote:

> i have a bunch of code that was working with integer arrays which i just
> converted to work with decimals.
>
> the array is in the database correctly. from psql, target_percentages is:
>
>  {0.08,0.08,0.09,0.08,0.08,0.09,0.08,0.08,0.09,0.08,0.08,0.09}

i the following alternate code to read the array:

                java.sql.Array tp = result.getArray( "target_percentages");
                target_percentages = getBigDecimalArray( tp, 12);

where getBigDecimalArray is as follows:


    public static BigDecimal [] getBigDecimalArray( java.sql.Array array, int len){
        BigDecimal [] bdarray = new BigDecimal [len];
        try {
            ResultSet rs = array.getResultSet();
            int index;
            BigDecimal num;
            while( rs.next()){
               index = rs.getInt( 1);
               bdarray[index - 1] = rs.getBigDecimal( 2);
            }
        } catch ( SQLException ex){
            Debug.println( "SQLException: " + ex.getMessage());
        }
        return bdarray;
    }

> this is postgresql 7.2.1-5 from an rpm on redhat 7.3, using the
> pgjdbc2.jar
> driver from october of  last year. the jdk is 1.4.1_01

i also updated to the pg72jdbc2.jar file from the pgjdbc website.

it is continuing to fail with the same error message,

SQLException: Bad BigDecimal 0.08

is there any known way to read an array of decimal values into a BigDecimal
array?

thanks,
  richard
--
Richard Welty                                         rwelty@averillpark.net
Averill Park Networking                                         518-573-7592
              Unix, Linux, IP Network Engineering, Security