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

一笑奈何 提交于 2019-12-11 03:04:49

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/1241512/cursor-is-closed-error-when-trying-to-execute-an-oracle-sp-using-jdbc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!