“光标已关闭”错误 - 尝试使用 JDBC 执行 Oracle SP 时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1241512/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 02:04:42  来源:igfitidea点击:

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

oracleexceptionjdbccursor

提问by Brian

The Oracle version of our database is 10g.

我们数据库的 Oracle 版本是 10g。

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

存储过程选择表中的所有元素并返回一个 REF CURSOR 类型,如下所示: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 中执行时,会得到以下异常——

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!

谢谢!

回答by Brian

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

调用存储过程的客户端负责关闭游标。请删除代码:CLOSE test_OUT;

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

客户端关闭它。在这种情况下,客户端是调用存储过程的 JDBC 程序。