Thread: parameter passing from java program

parameter passing from java program

From
"dfx"
Date:
Dear Sirs,
 
I am spending about 10 hours on little problem: to pass a parameter (text) to a PostgreSQL (v. 8.1 on Win2000). The
relevant code is:
 
java side:
private CallableStatement cs;
cs = conn.prepareCall(INSERT_CONGRESSO);
cs.setString(1, itemCongresso.getCongresso()); //return a String
cs.execute();
...
public static final String INSERT_CONGRESSO = "{SELECT ins_congressoa(?)}"; 
 
PostreSQL side:
CREATE OR REPLACE FUNCTION ins_congressoa(congresso text)
  RETURNS void AS
$BODY$INSERT INTO "Congressi" ("Congresso") VALUES ($1)
$BODY$
  LANGUAGE 'sql' VOLATILE;
ALTER FUNCTION ins_congressoa(congresso text) OWNER TO postgres;
 
With Pgadmin the function work fine, but from java program does not. WHY?
 
Thank you.
 
Domenico

Re: parameter passing from java program

From
Kris Jurka
Date:

On Mon, 15 May 2006, dfx wrote:

> I am spending about 10 hours on little problem: to pass a parameter (text)
> to a PostgreSQL (v. 8.1 on Win2000). The
> relevant code is:
>
> java side:
> private CallableStatement cs;
> cs = conn.prepareCall(INSERT_CONGRESSO);
> cs.setString(1, itemCongresso.getCongresso()); //return a String
> cs.execute();
> ...
> public static final String INSERT_CONGRESSO = "{SELECT ins_congressoa(?)}";
>

You're mixing your calling syntax.  You need to write either:

conn.prepareCall("{ ? = call ins_congressoa(?)}");

or

conn.prepareStatement("SELECT ins_congressoa(?)");

Kris Jurka