Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 895416331A6 for ; Sun, 12 Jul 2009 00:57:39 -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 01381-04 for ; Sun, 12 Jul 2009 00:57:28 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from kuber.nabble.com (kuber.nabble.com [216.139.236.158]) by mail.postgresql.org (Postfix) with ESMTP id B4DE8633144 for ; Sun, 12 Jul 2009 00:57:28 -0300 (ADT) Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1MPqBq-0002LV-FO for pgsql-jdbc@postgresql.org; Sat, 11 Jul 2009 20:57:26 -0700 Message-ID: <24445698.post@talk.nabble.com> Date: Sat, 11 Jul 2009 20:57:26 -0700 (PDT) From: "JAlexoid:Aleksandr Panzin" To: pgsql-jdbc@postgresql.org Subject: Re: calling a stored function which return set of records In-Reply-To: <4A5761B8.7030401@hdsnet.hu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Nabble-From: jalexoid@gmail.com References: <4A5761B8.7030401@hdsnet.hu> 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/17 X-Sequence-Number: 19785 You are creating the CallableStatement wrong. c.prepareCall("{ call get_recipe_kcal( ?,?,?,?,?,? ) }") Read more here: http://java.sun.com/javase/6/docs/technotes/guides/jdbc/getstart/callablest= atement.html#1003293 I suggest reading the whole thing here: http://java.sun.com/javase/6/docs/technotes/guides/jdbc/ Szab=C3=B3 Tam=C3=A1s wrote: >=20 > Hello! >=20 > I have a stored function in a postgresql databse, and I want to call it= =20 > from my java program. >=20 > The stored function is like this: >=20 > 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 >=20 > AS $$ >=20 > BEGIN >=20 > RETURN QUERY > SELECT recipes_ingredients_conn.recipe_id, > sum(recipes_ingredients_conn.amount / ingredients.amount *=20 > ingredients.kcal), > sum(recipes_ingredients_conn.amount / ingredients.amount *=20 > ingredients.kj), > sum(recipes_ingredients_conn.amount / ingredients.amount *=20 > ingredients.protein), > sum(recipes_ingredients_conn.amount / ingredients.amount *=20 > ingredients.fat), > sum(recipes_ingredients_conn.amount / ingredients.amount *=20 > ingredients.carbohydrates) >=20 > FROM recipes_ingredients_conn, ingredients > WHERE (recipes_ingredients_conn.ingredient_id =3D=20 > ingredients.ingredient_id) AND (recipes_ingredients_conn.recipe_id =3D=20 > recipe_id) > GROUP BY recipes_ingredients_conn.recipe_id; > END >=20 > $$ >=20 > LANGUAGE plpgsql; >=20 >=20 > The code sheet from my java program is like: >=20 > ... > // Turn transactions off. > c.setAutoCommit(false); > // Procedure call, i don't know if this is the right way to= =20 > define the stored function > // Maybe do i use a refcursor or something like this??? > CallableStatement upperProc =3D c.prepareCall("{ (?,?,?,?,?,?= )=20 > =3D call get_recipe_kcal( ? ) }"); > =20 > 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); >=20 > upperProc.setInt(7, 1); > =20 > upperProc.execute(); > double i =3D upperProc.getDouble(3); > =20 > System.out.println(i); > upperProc.close(); > ... >=20 > When I try to run the java program I get the following error message:=20 > 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=20 > about the problem, but I couldn't find a solution. > Please help me If you can. Thnaks! >=20 >=20 > --=20 > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-jdbc >=20 >=20 --=20 View this message in context: http://www.nabble.com/calling-a-stored-functi= on-which-return-set-of-records-tp24430047p24445698.html Sent from the PostgreSQL - jdbc mailing list archive at Nabble.com.