How to set numeric in PreparedStatement

From: Aaron Brashears <gila(at)gila(dot)org>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: How to set numeric in PreparedStatement
Date: 2001-03-22 07:20:56
Message-ID: 20010321232056.A10302@gila.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I want to set a numeric in a prepared statement, but I'm getting a
nasty exception for a simple query. The code is simple, and all I want
to do is query for a numeric type.

Here's the simplified data model:

create table account (
id varchar(3) primary key,
balance numeric(10,2));

And a code snippet that generates the exception:

...
PreparedStatement pstmt = connectoin.prepareStatement(
"select id from account where balance > ? and balance < ?";
pstmt.setDouble( 1, 10.0 );
pstmt.setDouble( 2, 100.0 );
ResultSet rs = pstmt.executeQuery();
...

And finally, the exception thrown:

Exception in thread "main" java.sql.SQLException: ERROR: Unable to identify an operator '>' for types 'numeric' and 'float8'
You will have to retype this query using an explicit cast

at org.postgresql.Connection.ExecSQL(Connection.java:398)
at org.postgresql.jdbc2.Statement.execute(Statement.java:273)
at org.postgresql.jdbc2.Statement.executeQuery(Statement.java:54)
at org.postgresql.jdbc2.PreparedStatement.executeQuery(PreparedStatement.java:101)
at SQLTest.main(SQLTest.java:16)

How can I accomplish this? I'm running postgresql 7.0.3 with the jdbc2
driver.

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Juhan-Peep Ernits 2001-03-22 08:12:16 Re: How to set numeric in PreparedStatement
Previous Message Bart 2001-03-21 23:58:24 Re: I can't connect