pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Gagnon <dgagnon@siunik.com>
To: Kris Jurka <books@ejurka.com>
Cc: pgsql-jdbc@postgresql.org
Cc: pgsql-general@postgresql.org
Subject: Re: [JDBC] plpgsql function with RETURNS SETOF refcursor AS. How to
Date: Thu, 24 Mar 2005 19:49:07 -0500
Message-ID: <42436003.3000509@siunik.com> (raw)
In-Reply-To: <Pine.BSO.4.56.0503241840570.31387@leary.csoft.net>
References: <42434D89.5080104@siunik.com>
	<Pine.BSO.4.56.0503241840570.31387@leary.csoft.net>

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




view thread (21+ messages)  latest in thread

Message-ID: <42436003.3000509@siunik.com>
Permalink:  ../42436003.3000509@siunik.com/
Also on:    postgresql.org/message-id/42436003.3000509@siunik.com

 · 

reply

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, books@ejurka.com, pgsql-general@postgresql.org
  Subject: Re: [JDBC] plpgsql function with RETURNS SETOF refcursor AS. How to
  In-Reply-To: <42436003.3000509@siunik.com>
  References: <42434D89.5080104@siunik.com> <Pine.BSO.4.56.0503241840570.31387@leary.csoft.net> <42436003.3000509@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