Re: Bug in PreparedStatement and 'numeric' columns

From: Barry Lind <barry(at)xythos(dot)com>
To: Daniel Serodio <daniel(at)checkforte(dot)com(dot)br>
Cc: PostgreSQL JDBC List <pgsql-jdbc(at)postgresql(dot)org>
Subject: Re: Bug in PreparedStatement and 'numeric' columns
Date: 2002-09-14 04:03:09
Message-ID: 3D82B4FD.6050008@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Daniel,

You should not have this problem if you use the latest version of the
driver (i.e. 7.3beta1 or the latest dev build) from jdbc.postgresql.org.

thanks,
--Barry

Daniel Serodio wrote:
> If I understand correctly, using a PreparedStatement I shouldn't have to
> "cast" anything in the SQL string, the driver should take care of that.
>
> However, I'm having problem using a column of type 'numeric'. The
> PreparedStatement.setBigDecimal(int, BigDecimal) javadoc states that
> "The driver converts this to an SQL NUMERIC value when it sends it to
> the database.". But version 7.2 of the PostgreSQL JDBC driver doesn't do
> this.
>
> Try the following:
>
> CREATE TABLE test (value numeric);
> INSERT INTO test VALUES (12.34);
>
> And in the Java code:
>
> PreparedStatement pStmt = connection.prepareStatement("SELECT * FROM
> test WHERE value = ?");
> pStmt.setBigDecimal(1, new BigDecimal("12.34"));
> ResultSet rs = pStmt.executeQuery();
>
> Throws the following SQLException:
> "ERROR: Unable to identify an operator '=' for types 'numeric' and
> 'double precision'
> You will have to retype this query using an explicit cast"
>
> Looking at the server's log, I see it received "SELECT * FROM test WHERE
> value = 12.34" instead of the "SELECT * FROM test WHERE value =
> 12.34::numeric" it should have received if setBigDecimal() was
> implemented the way the Javadoc says.
>
> So I think I have found a bug in the PostgreSQL JDBC driver, right?
>
>

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2002-09-14 19:09:18 JDBC Driver - Schema Awareness
Previous Message Dave Cramer 2002-09-14 00:58:05 Re: Retrieving ResultSets with millions of rows -