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






---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Reply via email to