From: Larry White <ljw1001@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: prepared statement call fails
Date: Sun, 5 Dec 2004 13:50:20 -0500
Message-ID: <d15ea14a0412051050399cd69b@mail.gmail.com> (raw)
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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: ljw1001@gmail.com
Subject: Re: prepared statement call fails
In-Reply-To: <d15ea14a0412051050399cd69b@mail.gmail.com>
References: <d15ea14a0412051050399cd69b@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox