Re: JDBC CallableStatement bug on functions with return parameter

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: <johnlh(at)aquafold(dot)com>
Cc: <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: JDBC CallableStatement bug on functions with return parameter
Date: 2011-02-05 17:43:33
Message-ID: 4D4D37E5020000250003A45D@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

John LH wrote:

> callStatement.registerOutParameter(1, java.sql.Types.FLOAT);

> callStatement.setObject(2, new Float(25.25));

PostgreSQL doesn't support using approximate data types (like Float)
for money. Try compiling and running this to see why:

import java.math.BigDecimal;
public class ExactnessTest
{
public static void main(String[] args)
{
double approximate;
BigDecimal exact;

// Set an approximation of a penny.
approximate = 0.01;
// Put the actual value into an exact class.
exact = new BigDecimal(approximate);
// Show the actual value assigned to the double.
System.out.println(exact);
// Create and show an exact decimal penny.
exact = new BigDecimal("0.01");
System.out.println(exact);
}
}

Try using BigDecimal, which *is* capable of storing exact
representations of all decimal fractions. Note that feeding an
approximate value, including an unquoted literal, to the BigDecimal
constructor will cause the BigDecimal value to be less precise than
you might expect.

-Kevin

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message John LH 2011-02-05 18:00:54 Re: JDBC CallableStatement bug on functions with return parameter
Previous Message John LH 2011-02-05 16:21:47 Re: JDBC CallableStatement bug on functions with return parameter