prepared statement call fails

From: Larry White <ljw1001(at)gmail(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: prepared statement call fails
Date: 2004-12-05 18:50:20
Message-ID: d15ea14a0412051050399cd69b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

I'm hoping someone with more experience can help me find a problem in
calling a function from Java. This is the first time I'm trying this
so I'm guessing it will be straightforward.

The function's signature is:

add_country(bigint, char(2), char(3), varchar(60))
RETURNS INTEGER '

It works fine if I call it from the command line, like so...

select add_country(124,'US', 'USA', 'United States of America');

In java, I call it using the following:

CallableStatement proc = null;
proc = connection.prepareCall("{ ? = call add_country( ? ? ? ? ) }");
proc.registerOutParameter(1, java.sql.Types.INTEGER);
proc.setInt(2, 124);
proc.setString(3, code2); // a two character java String
proc.setString(4, code3); // a three character java String
proc.setString(5, name); // a Java String
proc.execute();

with the result that I get the exception:

ERROR: syntax error at or near "'JA'" at character 33

(where JA is whatever I'm passing in my second in parameter - defined
as char(2).

I've inspected the input Strings just before calling to make sure
they're what I expected.

Is there a mapping published between JDBC statements and Postgresql
types? One possibility seems to be that either the char(x) types
don't like Strings or the setInt(x,y) doesn't work with BIGINTs, but
I'm just guessing.

Any help at all would be greatly appreciated. Thanks.

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Michael Fuhr 2004-12-05 18:57:20 Re: SSL confirmation
Previous Message Andrew M 2004-12-05 18:37:57 Re: SSL confirmation