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 SQLTest.main(SQLTest.java:16)

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

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Reply via email to