存储过程
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)
我不知道为什么它会显示这样的错误。请纠正我的错误。