Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YymbA-0006So-Hk for pgsql-jdbc@arkaria.postgresql.org; Sat, 30 May 2015 19:39:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Yymb9-0006IB-Ke for pgsql-jdbc@arkaria.postgresql.org; Sat, 30 May 2015 19:39:11 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Yymb7-0006I2-Fm for pgsql-jdbc@postgresql.org; Sat, 30 May 2015 19:39:09 +0000 Received: from rad0.itstriangle.com ([199.38.107.90]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Yymb2-0005cN-NL for pgsql-jdbc@postgresql.org; Sat, 30 May 2015 19:39:06 +0000 Received: from itstriangle.com (localhost [127.0.0.1]) by rad0.itstriangle.com (8.14.4/8.14.4) with ESMTP id t4UJcuoO005537; Sat, 30 May 2015 15:38:57 -0400 Received: FROM [192.168.157.52] ([216.220.4.222]) BY itstriangle.com WITH ESMTP ; Sat, 30 May 2015 15:38:55 -0400 Message-ID: <556A1477.2050506@ttc-cmc.net> Date: Sat, 30 May 2015 13:50:15 -0600 From: dmp User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Firefox/24.0 SeaMonkey/2.21 MIME-Version: 1.0 To: Thomas Kellerer , PostgreSQL JDBC Subject: Re: CallableStatement.getParameterMetaData() throws exception for valid {call ...} statement References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-15; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Thomas Kellerer wrote: > Hello, > > I just noticed the following: > > Using this sample function from the manual: > > CREATE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS $$ > BEGIN > sum := x + y; > prod := x * y; > END; > $$ LANGUAGE plpgsql; > > > When calling this through JDBC, the following works without problems: > > cstmt = connection.prepareCall("{call sum_n_product(?,?,?,?)}"); > cstmt.registerOutParameter(3, Types.INTEGER); > cstmt.registerOutParameter(4, Types.INTEGER); > cstmt.setInt(1, 2); > cstmt.setInt(2, 5); > cstmt.execute(); > int x1 = cstmt.getInt(3); > int x2 = cstmt.getInt(4); > > System.out.println("x1: " + x1); > System.out.println("x2: " + x2); > > However when calling > > ParameterMetaData meta = cstmt.getParameterMetaData(); > > after prepareCall() the following exception is thrown: > > org.postgresql.util.PSQLException: ERROR: function sum_n_product(unknown, > unknown, unknown, unknown) does not exist > Hint: No function matches the given name and argument types. You might > need to add explicit type casts. > Position: 15 > > Casting everything to integer ( "{call > sum_n_product(?::int,?::int,?::int,?::int)}" ) produces the same error (except > that the parameter list shows integer in the exception message). > > This looks like a bug to me. Why should getParameterMetaData() throw an > exception if the call is valid and working? > > Driver version is 9.4-1200 > Postgres version is 9.4.2 > Java version is 1.7.0_55 > > Regards > Thomas Hello, Seems to work fine, maybe I have it wrong? danap. private void testCallableStatement2(Connection connection) { // Method Instances String sqlStatementString; Statement sqlStatement; CallableStatement cstmt; ParameterMetaData meta; try { // Setup a connection statement. sqlStatement = connection.createStatement(); // Create Function. //sqlStatementString = "DROP FUNCTION sum_n_product(int, int, OUT int, OUT int)"; //sqlStatement.execute(sqlStatementString); sqlStatementString = "CREATE OR REPLACE FUNCTION sum_n_product(x int, y int, OUT sum int, OUT prod int) AS $$" + " SELECT (x + y) AS sum, (x * y) AS prod; $$ LANGUAGE SQL;"; System.out.println(sqlStatementString); sqlStatement.execute(sqlStatementString); // Execute Function. cstmt = connection.prepareCall("{call sum_n_product(?,?,?,?)}"); cstmt.registerOutParameter(3, Types.INTEGER); cstmt.registerOutParameter(4, Types.INTEGER); cstmt.setInt(1, 2); cstmt.setInt(2, 5); cstmt.execute(); meta = cstmt.getParameterMetaData(); System.out.println("Parameter Count: " + meta.getParameterCount()); int x1 = cstmt.getInt(3); int x2 = cstmt.getInt(4); System.out.println("x1: " + x1); System.out.println("x2: " + x2); // Drop Function. sqlStatementString = "DROP FUNCTION sum_n_product(int, int, OUT int, OUT int);"; System.out.println(sqlStatementString); sqlStatement.execute(sqlStatementString); cstmt.close(); sqlStatement.close(); } catch (SQLException sqle) { System.out.println("SQL Exeception" + sqle); } } -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc