pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Brady S Edwards <brady.s.edwards@seagate.com>
To: pgsql-jdbc@postgresql.org
Subject: JDBC parameter binding not working for PL/PGSQL block JDBC3 Version 9.0-801
Date: Wed, 27 Apr 2011 14:11:38 -0600
Message-ID: <BANLkTi=VpazmODCUShc5a+WNaf4uspf5fA@mail.gmail.com> (raw)
In-Reply-To: <BANLkTi=vNEroPFa159HUw9DcxWuj=yHSwA@mail.gmail.com>
References: <BANLkTi=vNEroPFa159HUw9DcxWuj=yHSwA@mail.gmail.com>

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



view thread (5+ messages)  latest in thread

Message-ID: <BANLkTi=VpazmODCUShc5a+WNaf4uspf5fA@mail.gmail.com>
Permalink:  ../BANLkTi=VpazmODCUShc5a+WNaf4uspf5fA@mail.gmail.com/
Also on:    postgresql.org/message-id/BANLkTi=VpazmODCUShc5a+WNaf4uspf5fA@mail.gmail.com

 · 

reply

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: brady.s.edwards@seagate.com
  Subject: Re: JDBC parameter binding not working for PL/PGSQL block JDBC3 Version 9.0-801
  In-Reply-To: <BANLkTi=VpazmODCUShc5a+WNaf4uspf5fA@mail.gmail.com>
  References: <BANLkTi=vNEroPFa159HUw9DcxWuj=yHSwA@mail.gmail.com> <BANLkTi=VpazmODCUShc5a+WNaf4uspf5fA@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