gpt4 book ai didi

java - 从 oracle 执行方法中检索返回值

转载 作者:太空宇宙 更新时间:2023-11-04 13:55:47 24 4
gpt4 key购买 nike

我读到了 Oracle 中的execute 和executeQuery 方法之间的差异,并看到了下面的文本

executeQuery() — This is used generally for reading the content of the database. The output will be in the form of ResultSet. Generally SELECT statement is used.

execute() — If you dont know which method to be used for executing SQL statements, this method can be used. This will return a boolean. TRUE indicates the result is a ResultSet and FALSE indicates it has the int value which denotes number of rows affected by the query.

这是我的问题。我使用execute方法执行一个过程,但它只返回一个整数值。我像这样检索返回值:

stmt.execute(); 
output = stmt.getInteger(1);
close(stmt); // statement
close(connection); // connection

我在这里不使用 ResultSet 对象,因此我不会显式关闭 ResultSet 之类的东西。因此,根据上面的文本,如果执行函数返回结果集,那么我的代码中的结果集会发生什么?它保持打开状态吗?如果是的话,我该如何关闭它?

最佳答案

CallableStatement.getInt()ResultSet 无关,它与存储过程的输出参数相关。如果您的存储过程返回游标,那么您必须使用 getResultSet() 并处理其中的结果。

关于关闭 - 关闭 Statement 并不强制要求所有基于它的 ResultSet 也被关闭,并且 IIRC,使用 Oracle JDBC 驱动程序,在 Statement 关闭后,ResultSet 确实可能保持打开状态。因此,如果它存在,您必须显式关闭它。

关于java - 从 oracle 执行方法中检索返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29846417/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com