JDBC parameter binding not working for PL/PGSQL block JDBC3 Version 9.0-801

From: Brady S Edwards <brady(dot)s(dot)edwards(at)seagate(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: JDBC parameter binding not working for PL/PGSQL block JDBC3 Version 9.0-801
Date: 2011-04-27 20:11:38
Message-ID: BANLkTi=VpazmODCUShc5a+WNaf4uspf5fA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Had a slight problem in the Java that I fixed but the error is still the same.

Database postgresql90-server-9.0.2-1PGDG.rhel4
CentOS 4.7
JDBC3 Version 9.0-901.

I'm working on a project converting a number of applications from
Oracle to Postgres and am running into a problem with the Postgres
JDBC driver or the database.

When trying to setString(1,?) where the ? is in a pl/pgsql block I get an error.
I included the error and portion of the code:

/mnt/ae_files/users/brady/postgres> java WhatTheF
Trying to connect
Looks like connections succeeded

Bound Vars = 1
Bound Vars = 0
org.postgresql.util.PSQLException: The column index is out of range:
1, number of columns: 0.
at org.postgresql.core.v3.SimpleParameterList.bind(SimpleParameterList.java:53)
at org.postgresql.core.v3.SimpleParameterList.setStringParameter(SimpleParameterList.java:118)
at org.postgresql.jdbc2.AbstractJdbc2Statement.bindString(AbstractJdbc2Statement.java:2184)
at org.postgresql.jdbc2.AbstractJdbc2Statement.setString(AbstractJdbc2Statement.java:1303)
at org.postgresql.jdbc2.AbstractJdbc2Statement.setString(AbstractJdbc2Statement.java:1289)
at WhatTheF.main(WhatTheF.java:35)

try {
System.out.println("Trying to connect");
Class.forName ("org.postgresql.Driver");
Properties props = new Properties();
props.setProperty("user", PG_USER);
props.setProperty("password", PG_PASS);
Connection pgConn = DriverManager.getConnection(PG_CONN_PROP, props);
System.out.println("Looks like connections succeeded\n");
PreparedStatement pStmt = pgConn.prepareStatement(
"INSERT INTO soo (zoo) values (?)");
ParameterMetaData pmd = pStmt.getParameterMetaData();
System.out.println("Bound Vars = " + pmd.getParameterCount());
pStmt.setString(1, "Monkey");
pStmt.executeUpdate();
pStmt.close();
pStmt = pgConn.prepareCall(
" DO LANGUAGE plpgsql "
+ " $$\n"
+ " DECLARE\n"
+ " BEGIN\n"
+ " INSERT INTO soo (zoo) values (?);\n"
+ " END $$;");
pmd = pStmt.getParameterMetaData();
System.out.println("Bound Vars = " + pmd.getParameterCount());
LINE 35 -> pStmt.setString(1, "Barf");
pStmt.executeUpdate();
pStmt.close();
pgConn.close();
}
catch (Exception e) {
e.printStackTrace();
}

I'm guessing that anonymous plpgsql blocks cannot take input parameters.

--
Brady Edwards
(720) 684-2984
Seagate Technology

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Oliver Jowett 2011-04-27 20:17:39 Re: JDBC parameter binding not working for PL/PGSQL block JDBC3 Version 9.0-801
Previous Message Brady S Edwards 2011-04-27 19:35:53 JDBC parameter binding not working for PL/PGSQL block JDBC3 Version 9.0-801