JDBC调用程序包下的存储过程,返回结果集为空
包头:
CREATE OR REPLACE
PACKAGE PACKAGE1 AS
type empcursor is ref cursor;
procedure queryEmpList(dept in number,empList out empcursor);
END PACKAGE1;
包体:
CREATE OR REPLACE
PACKAGE BODY PACKAGE1 AS
procedure queryEmpList(dept in number,empList out empcursor) AS
BEGIN
--打开光标
open empList for select * from class_0902 where dept=dept;
END queryEmpList;
END PACKAGE1;
java:
@Test
public void testCursor() {
String sql = "{call PACKAGE1.queryEmpList(?,?)}";
Connection conn = null;
CallableStatement call = null;
ResultSet rs = null;
try {
conn = JDBCUtils.getConnection();
call = conn.prepareCall(sql);
//赋值输入参数
call.setInt(1, 10);
//声明输出参数
call.registerOutParameter(2, OracleTypes.CURSOR);
//执行调用
call.execute();
//取出该部门所有员工的信息
rs = ((OracleCallableStatement)call).getCursor(2);
System.out.println(rs.next);
while(rs.next()) {
String name = rs.getString("name");
Double empno = rs.getDouble("emp_no");
Double salary = rs.getDouble("salary");
Double comm = rs.getDouble("comm");
System.out.println(empno + "\t" + name + "\t" + salary + "\t" + comm);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
JDBCUtils.release(conn, call, rs);
}
}
控制台输出为false