Re: [JDBC] plpgsql function with RETURNS SETOF refcursor AS. How to

From: David Gagnon <dgagnon(at)siunik(dot)com>
To: Kris Jurka <books(at)ejurka(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org
Subject: Re: [JDBC] plpgsql function with RETURNS SETOF refcursor AS. How to
Date: 2005-03-25 00:49:07
Message-ID: 42436003.3000509@siunik.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-jdbc

Hi Kris,

I don't get error with the rsTmp.close() statement but with "
(rsTmp.next()) ". The arraycopy is because I want to shrink the
original array (size 50) to it real size. It's not intended to be a
deep copy.

Plpgsql function can return multiple refcursor .. so the question is how
I can get them via JDBC? Below I included the function that doen't work
(throw exception in the while condition). I also included a "WORKING"
function that actually return only one refcursor.

Thanks for your help .. if you see something wrong I'll be happy to know
it :-)

/David

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;
}

public ResultSet executePreparedStatementQueryCursor() throws
SQLException {
ResultSet rsTmp = ps.executeQuery();
rs = new ResultSet[1];
rs[0] = (ResultSet) rsTmp.getObject(1);
rsTmp.close();
return rs[0];
}

Kris Jurka wrote:

>On Thu, 24 Mar 2005, David Gagnon wrote:
>
>
>
>> 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.
>>
>>
>> rs = new ResultSet[j];
>> System.arraycopy(tempArray, 0, rs, 0, j);
>> rsTmp.close();
>>
>>
>
>System.arraycopy does not make a deep copy, so the rsTmp.close() closes
>the ResultSet. You really can't copy resources around like that.
>Consider how you would copy a Connection object. Does that establish a
>new connection? The underlying tcp/ip connection can't be copied.
>
>Kris Jurka
>
>
>
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kris Jurka 2005-03-25 01:14:41 Re: [JDBC] plpgsql function with RETURNS SETOF refcursor AS. How
Previous Message Guy Rouillier 2005-03-25 00:29:56 Re: Converting from single user w/pool to multiple users

Browse pgsql-jdbc by date

  From Date Subject
Next Message Kris Jurka 2005-03-25 01:14:41 Re: [JDBC] plpgsql function with RETURNS SETOF refcursor AS. How
Previous Message Kris Jurka 2005-03-24 23:45:28 Re: [Patch] JDBC3 Blob support