X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 33FEC53457; Thu, 24 Mar 2005 23:26:58 +0000 (GMT) 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 02092-08; Thu, 24 Mar 2005 23:26:57 +0000 (GMT) Received: from relais.videotron.ca (relais.videotron.ca [24.201.245.36]) by svr1.postgresql.org (Postfix) with ESMTP id B32085342F; Thu, 24 Mar 2005 23:26:55 +0000 (GMT) Received: from [192.168.1.100] ([24.202.23.128]) by VL-MO-MR011.ip.videotron.ca (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep 8 2003)) with ESMTP id <0IDV00GYCQGXYW@VL-MO-MR011.ip.videotron.ca>; Thu, 24 Mar 2005 18:26:58 -0500 (EST) Date: Thu, 24 Mar 2005 18:30:17 -0500 From: David Gagnon Subject: plpgsql function with RETURNS SETOF refcursor AS. How to get it work via JDBC To: pgsql-jdbc@postgresql.org, pgsql-general@postgresql.org Message-id: <42434D89.5080104@siunik.com> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.017 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200503/1232 X-Sequence-Number: 75547 Hi all, I'm already able to get Refcursor from a stored procedure. But now I need to get a SETOF refcursor and I can't make it work... Is that possible to do this via JDBC? He is the code I did. The rsTmp.next() throws a Connection is closed. Operation is not permitted. Exception. public ResultSet[] executePreparedStatementQueryMultipleCursor() throws SQLException { ResultSet rsTmp = ps.executeQuery(); ResultSet[] tempArray = new ResultSet[50]; // Should be enough int j = 0; while (rsTmp.next()) { tempArray[j] = (ResultSet) rsTmp.getObject(1); j++; } rs = new ResultSet[j]; System.arraycopy(tempArray, 0, rs, 0, j); rsTmp.close(); return rs; } Here is a part of my function (see below) wich seems to work correctly. If it's not supported is there a workaround? Is this supposed to be supported sooner? Thanks for your help it's really appreciated! /David CREATE OR REPLACE FUNCTION usp_Comptabilite_JournalVentes(VARCHAR, DATE, DATE, VARCHAR,VARCHAR) RETURNS SETOF refcursor AS ' DECLARE companyId ALIAS FOR $1; startDate ALIAS FOR $2; endDate ALIAS FOR $3; periodIdFrom ALIAS FOR $4; periodIdTo ALIAS FOR $5; ref1 refcursor; ref2 refcursor; statement varchar(4000); appliedStr varchar(10); printedStr varchar(10); BEGIN .... OPEN ref1 FOR EXECUTE statement; RETURN NEXT ref1; ... OPEN ref2 FOR EXECUTE statement; RETURN NEXT ref2; RETURN; END; ' LANGUAGE 'plpgsql';