StoredProcedure的
create or replace procedure my_procedure
is
cursor c_emp is select * from employees;
r_name c_emp%rowtype;
begin
open c_emp;
loop
fetch c_emp into r_name;
DBMS_OUTPUT.PUT_LINE(r_name.EMP_NAME);
EXIT WHEN c_emp%NOTFOUND;
END LOOP;
close c_emp;
END;
JDBC代码
stmt=conn.prepareCall("{call my_procedure}");
stmt.registerOutParameter(1, java.sql.Types.VARCHAR);
ResultSet rs = stmt.executeQuery();
while(rs.next()) {
System.out.println( rs.getString(1));
}
显示错误,如
错误:
java.sql.SQLException: Invalid column index
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:113)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:147)
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:209)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameterInternal(OracleCallableStatement.java:122)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:285)
at oracle.jdbc.driver.OracleCallableStatement.registerOutParameter(OracleCallableStatement.java:371)
at table.callstmt_storedprcd.main(callstmt_storedprcd.java:27)
我不知道为什么会出现这样的错误。请纠正我的错误。
答案 0 :(得分:1)
DBMS_OUTPUT用于向屏幕显示消息。它不是OUT参数。
您的程序没有参数。因此,这将打破你的计划:
stmt.registerOutParameter(1, java.sql.Types.VARCHAR);