Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id C7FF61AE2382 for ; Thu, 24 Nov 2011 00:13:26 -0400 (AST) Received: from sam.nabble.com ([216.139.236.26]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RTQgc-0001rV-WC for pgsql-jdbc@postgresql.org; Thu, 24 Nov 2011 04:13:25 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1RTQgO-0000rD-HL for pgsql-jdbc@postgresql.org; Wed, 23 Nov 2011 20:13:08 -0800 Date: Wed, 23 Nov 2011 20:13:08 -0800 (PST) From: JavaNoobie To: pgsql-jdbc@postgresql.org Message-ID: <1322107988531-5019196.post@n5.nabble.com> Subject: CallableStatement PostgreSQL Error:A CallableStatement was executed with an invalid number of parameters MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 201111/88 X-Sequence-Number: 22423 Hi All, Im trying to write sample stored functions in postgresql and call them using the CallableStatement offered by JDBC. Here's some my test code [code=java] Consumer bean =new Consumer(); CallableStatement pstmt = null; try { con.setAutoCommit(false); String query = "{ ? = call getData( ? ) }"; pstmt = con.prepareCall(query); pstmt.registerOutParameter(1, Types.OTHER); pstmt.setInt(2,5); pstmt.execute(); // execute update statement bean=(Consumer)pstmt.getObject(1); System.out.println("bean"+bean.getConsumer_name()); ..... [/code] And my Stored function is of the form . [code=sql] CREATE FUNCTION getData(int) RETURNS SETOF db_consumer AS $$ SELECT * FROM db_consumer WHERE consumer_id = $1; $$ LANGUAGE SQL; [/code] However, I'm getting the following error when I try to run the code . [code=java] org.postgresql.util.PSQLException: A CallableStatement was executed with an invalid number of parameters at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:408) at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:381) at com.enzen.cis.dao.Updatetest.main(Updatetest.java:44) [/code] Any idea on why this is happening would be appreciated. -- View this message in context: http://postgresql.1045698.n5.nabble.com/CallableStatement-PostgreSQL-Error-A-CallableStatement-was-executed-with-an-invalid-number-of-parames-tp5019196p5019196.html Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.