From: David Gagnon <dgagnon@siunik.com>
To: pgsql-jdbc@postgresql.org
To: pgsql-general@postgresql.org
Subject: plpgsql function with RETURNS SETOF refcursor AS. How to get it work via JDBC
Date: Thu, 24 Mar 2005 18:30:17 -0500
Message-ID: <42434D89.5080104@siunik.com> (raw)
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';
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: dgagnon@siunik.com, pgsql-general@postgresql.org
Subject: Re: plpgsql function with RETURNS SETOF refcursor AS. How to get it work via JDBC
In-Reply-To: <42434D89.5080104@siunik.com>
References: <42434D89.5080104@siunik.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox