Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 095451337BC4 for ; Wed, 27 Apr 2011 17:23:29 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 42036-05 for ; Wed, 27 Apr 2011 20:23:10 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx0a-000cda01.pphosted.com (mx0a-00003501.pphosted.com [67.231.144.15]) by mail.postgresql.org (Postfix) with ESMTP id B2E471337D23 for ; Wed, 27 Apr 2011 17:11:59 -0300 (ADT) Received: from pps.filterd (m0004061 [127.0.0.1]) by mx0a-000cda01.pphosted.com (8.14.4/8.14.4) with SMTP id p3RK7nJ5023395 for ; Wed, 27 Apr 2011 16:11:58 -0400 Received: from mail-iw0-f170.google.com (mail-iw0-f170.google.com [209.85.214.170]) by mx0a-000cda01.pphosted.com with ESMTP id vxstc02w7-3 (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NOT) for ; Wed, 27 Apr 2011 16:11:58 -0400 Received: by mail-iw0-f170.google.com with SMTP id 3so2095706iwn.15 for ; Wed, 27 Apr 2011 13:11:58 -0700 (PDT) Received: by 10.231.64.148 with SMTP id e20mr2047548ibi.91.1303935118117; Wed, 27 Apr 2011 13:11:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.231.19.196 with HTTP; Wed, 27 Apr 2011 13:11:38 -0700 (PDT) In-Reply-To: References: From: Brady S Edwards Date: Wed, 27 Apr 2011 14:11:38 -0600 Message-ID: Subject: JDBC parameter binding not working for PL/PGSQL block JDBC3 Version 9.0-801 To: pgsql-jdbc@postgresql.org Content-Type: text/plain; charset=UTF-8 X-Proofpoint-PolicyRoute: Outbound X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.2.15, 1.0.148, 0.0.0000 definitions=2011-04-27_07:2011-04-27, 2011-04-27, 1970-01-01 signatures=0 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 ipscore=0 suspectscore=3 phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=6.0.2-1012030000 definitions=main-1104270138 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201104/97 X-Sequence-Number: 21823 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