Thursday, April 21, 2011

"Cursor is closed" error - when trying to execute an Oracle SP using JDBC

The Oracle version of our database is 10g.

The stored procedure selects all the elements in a table and returns a REF CURSOR type as follows: create or replace

PROCEDURE S_S_TEST( 
  test_OUT OUT OAS_TYPES.REFCURSOR
) 
AS
BEGIN
  OPEN test_OUT FOR      
      SELECT *
      FROM table_p;
   CLOSE test_OUT;
END S_S_TEST;

When this stored procedure is executed in JAVA the following exception is obtained-

java.sql.SQLException: Cursor is closed. at oracle.jdbc.driver.T4CResultSetAccessor.getCursor(T4CResultSetAccessor.java:323) at oracle.jdbc.driver.ResultSetAccessor.getObject(ResultSetAccessor.java:85) at oracle.jdbc.driver.OracleCallableStatement.getObject(OracleCallableStatement.java:1401) at com.ibm.ws.rsadapter.jdbc.WSJdbcCallableStatement.getObject(WSJdbcCallableStatement.java:443)

I am trying to understand what the error is and how it could be fixed. Could someone please help me out?

Thanks!

From stackoverflow
  • The client calling the stored procedure is responsible for closing the cursor. Please remove the code: CLOSE test_OUT;

    The client closes it. In this case the client is the JDBC program that calls the stored procedure.

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.