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 614F5329CBC for ; Sat, 11 Sep 2004 08:41:06 +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 24384-03 for ; Sat, 11 Sep 2004 07:40:47 +0000 (GMT) Received: from yass.opencloud.co.nz (yass.opencloud.co.nz [203.79.85.162]) by svr1.postgresql.org (Postfix) with ESMTP id B0152329C65 for ; Sat, 11 Sep 2004 08:40:48 +0100 (BST) Received: from 203-79-104-60.cable.paradise.net.nz ([203.79.104.60] helo=opencloud.com) by yass.opencloud.co.nz with asmtp (Exim 3.35 #1 (Debian)) id 1C62V4-0006dv-00; Sat, 11 Sep 2004 19:40:46 +1200 Message-ID: <4142ABFC.6020401@opencloud.com> Date: Sat, 11 Sep 2004 19:40:44 +1200 From: Oliver Jowett User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Leo Martin Orfei Cc: pgsql-jdbc@postgresql.org Subject: Re: problems returning a resultset from a function References: <20040904160747.66889.qmail@web51806.mail.yahoo.com> In-Reply-To: <20040904160747.66889.qmail@web51806.mail.yahoo.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit 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/39 X-Sequence-Number: 10929 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