X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id EC119329E6A for ; Sat, 11 Sep 2004 16:23:51 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 45871-09 for ; Sat, 11 Sep 2004 15:23:50 +0000 (GMT) Received: from web51802.mail.yahoo.com (web51802.mail.yahoo.com [206.190.38.233]) by svr1.postgresql.org (Postfix) with SMTP id 0DD6A329E5D for ; Sat, 11 Sep 2004 16:23:49 +0100 (BST) Message-ID: <20040911152348.19135.qmail@web51802.mail.yahoo.com> Received: from [201.255.82.147] by web51802.mail.yahoo.com via HTTP; Sat, 11 Sep 2004 08:23:48 PDT Date: Sat, 11 Sep 2004 08:23:48 -0700 (PDT) From: Leo Martin Orfei Subject: Re: problems returning a resultset from a function To: Oliver Jowett Cc: pgsql-jdbc@postgresql.org In-Reply-To: <4142ABFC.6020401@opencloud.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200409/40 X-Sequence-Number: 10930 Thanks a lot. This really solve my problem. regards. --- Oliver Jowett wrote: > Leo Martin Orfei wrote: > > [.. declare function returning refcursor ..] > > > CallableStatement cs = null; > > ResultSet rs = null; > > cs = con.prepareCall("{ ? = call test()}"); > > cs.registerOutParameter(1, java.sql.Types.OTHER); > > rs = cs.executeQuery(); > > rs.next(); > > System.out.println("name: " +rs.getString(1)); > > > > but throws te following error: > > > > cursor "" does not exist > > Check that you have called > Connection.setAutoCommit(false). If > autocommit is on, your returned cursor will be > closed as soon as the > transaction (auto)commits, so the subsequent select > done to fetch the > portal contents will fail. > > A '? = call' escape does not return a resultset. You > should use the > CallableStatement.get...() methods to retrieve the > values of the out > parameter. You will likely see errors complaining > about no resultset > being returned from executeQuery() once you fix the > autocommit setting. > > The refcursor is returned as a ResultSet (as the > out-parameter value) > i.e. CallableStatement.getObject(1) will return a > ResultSet that has the > contents of the refcursor. > > See > http://www.postgresql.org/docs/current/static/jdbc-callproc.html > for > some example code on using callable statements and > refcursor-returning > functions. (note that using PGRefCursorResultSet is > deprecated; just use > getString() to obtain the cursor name). > > -O > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com