无法对PLSQL语句执行访存:下一步 [英] Cannot perform fetch on a PLSQL statement: next
本文介绍了无法对PLSQL语句执行访存:下一步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
存储过程
CREATE OR REPLACE
PROCEDURE ADDITION
(
A IN NUMBER ,
B IN NUMBER ,
C OUT NUMBER )
AS
BEGIN
C := A+B;
dbms_output.put_line(c);
END ADDITION;
JDBC程序
cstmt = conn.prepareCall("BEGIN addition(?, ?,?); END;");
cstmt.setInt(1, 10);
cstmt.setInt(2, 85);
cstmt.registerOutParameter(3, java.sql.Types.INTEGER);
ResultSet rs = cstmt.executeQuery();
while(rs.next()){
int c =rs.getInt("c");
System.out.println(c);
}
在执行上述程序时出现错误.
while executing above program program am getting error.
Eroor:
java.sql.SQLException: Cannot perform fetch on a PLSQL statement: next
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:147)
at oracle.jdbc.driver.OracleResultSetImpl.next(OracleResultSetImpl.java:192)
at stored_procedure.main(stored_procedure.java:32)
我希望有人能帮助我解决此错误.
I hope Could any one help me for how to resolve this error.
推荐答案
executeQuery()
设计用于处理返回游标(通常是SELECT
查询)的sql语句.
您的呼叫不返回游标,因此不适用于此方法.您应该只使用execute()
,然后从输出参数中获取值:
executeQuery()
is designed to work with sql statements that return a cursor (most often, a SELECT
query).
Your call does not return a cursor, and is thus inappropriate for use with this method. You should just use execute()
, and then get the value from the output parameter:
cstmt = conn.prepareCall("BEGIN addition(?, ?,?); END;");
cstmt.setInt(1, 10);
cstmt.setInt(2, 85);
cstmt.registerOutParameter(3, java.sql.Types.INTEGER);
cstmt.execute();
int c = cstmt.getInt(3);
System.out.println(c);
这篇关于无法对PLSQL语句执行访存:下一步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文