Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 24003634505 for ; Fri, 10 Jul 2009 12:50:30 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 80658-09 for ; Fri, 10 Jul 2009 12:50:18 -0300 (ADT) X-Greylist: delayed 00:06:36.411735 by SQLgrey-1.7.6 Received: from smtp.opticon.hu (smtp.opticon.hu [195.56.234.123]) by mail.postgresql.org (Postfix) with SMTP id 0278C6346AA for ; Fri, 10 Jul 2009 12:50:18 -0300 (ADT) Received: (qmail 16004 invoked from network); 10 Jul 2009 15:43:37 -0000 Received: from unknown (HELO ?192.168.1.12?) (85.66.103.79) by smtp.opticon.hu with SMTP; 10 Jul 2009 15:43:37 -0000 Message-ID: <4A5761B8.7030401@hdsnet.hu> Date: Fri, 10 Jul 2009 17:43:52 +0200 From: =?ISO-8859-2?Q?Szab=F3_Tam=E1s?= User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 To: pgsql-jdbc@postgresql.org Subject: calling a stored function which return set of records Content-Type: text/plain; charset=ISO-8859-2; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200907/16 X-Sequence-Number: 19784 Hello! I have a stored function in a postgresql databse, and I want to call it from my java program. The stored function is like this: CREATE OR REPLACE FUNCTION get_recipe_data(recipe_id integer, OUT recipe_id integer, OUT kcal real, OUT kj real, OUT protein real, OUT fat real, OUT carbohydrates real ) RETURNS SETOF record AS $$ BEGIN RETURN QUERY SELECT recipes_ingredients_conn.recipe_id, sum(recipes_ingredients_conn.amount / ingredients.amount * ingredients.kcal), sum(recipes_ingredients_conn.amount / ingredients.amount * ingredients.kj), sum(recipes_ingredients_conn.amount / ingredients.amount * ingredients.protein), sum(recipes_ingredients_conn.amount / ingredients.amount * ingredients.fat), sum(recipes_ingredients_conn.amount / ingredients.amount * ingredients.carbohydrates) FROM recipes_ingredients_conn, ingredients WHERE (recipes_ingredients_conn.ingredient_id = ingredients.ingredient_id) AND (recipes_ingredients_conn.recipe_id = recipe_id) GROUP BY recipes_ingredients_conn.recipe_id; END $$ LANGUAGE plpgsql; The code sheet from my java program is like: ... // Turn transactions off. c.setAutoCommit(false); // Procedure call, i don't know if this is the right way to define the stored function // Maybe do i use a refcursor or something like this??? CallableStatement upperProc = c.prepareCall("{ (?,?,?,?,?,?) = call get_recipe_kcal( ? ) }"); upperProc.registerOutParameter(1, Types.INTEGER); upperProc.registerOutParameter(2, Types.REAL); upperProc.registerOutParameter(3, Types.REAL); upperProc.registerOutParameter(4, Types.REAL); upperProc.registerOutParameter(5, Types.REAL); upperProc.registerOutParameter(6, Types.REAL); upperProc.setInt(7, 1); upperProc.execute(); double i = upperProc.getDouble(3); System.out.println(i); upperProc.close(); ... When I try to run the java program I get the following error message: Error: Malformed function or procedure escape syntax at offset 2. I don't really know what I'm doing wrong, i read through some articles about the problem, but I couldn't find a solution. Please help me If you can. Thnaks!