JDBC調(diào)用程序包下的存儲(chǔ)過程,返回結(jié)果集為空
包頭:
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
? ? --打開光標(biāo)
? ? 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);
//賦值輸入?yún)?shù)
call.setInt(1, 10);
//聲明輸出參數(shù)
call.registerOutParameter(2, OracleTypes.CURSOR);
//執(zhí)行調(diào)用
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);
}
}
控制臺(tái)輸出為false