當我從休眠狀態調用存儲過程時。結果集只返回一行,但在數據庫表中有四行數據。使用hibernate- ResultSet調用Oracle過程只返回第一行數據,缺少行數據缺失
這裏我附上了來自db的表格和數據的細節。
表名稱:TBL_EMPLOYEES
**Procedure :**
create or replace PROCEDURE "SP_GET_EMPLOYEES" (
ecur OUT sys_refcursor)
AS
BEGIN
OPEN ecur FOR
SELECT *FROM TBL_EMPLOYEES;
END;
Java代碼的(呼叫甲骨文在休眠存儲過程)
Session session = HibernateSessionManager.getSessionFactory()
.openSession();
session.beginTransaction();
try {
session.doWork(new Work() {
public void execute(Connection connection) {
CallableStatement call;
try {
String aProcedureName="SP_GET_EMPLOYEES";
String functionCall = "{call " + aProcedureName + "(?)}";
call = connection.prepareCall(functionCall);
call.registerOutParameter(1, OracleTypes.CURSOR);
call.execute();
ResultSet rs=(ResultSet) call.getObject(1);
if(rs.next()){
System.out.println(rs.getString(1));
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// propagate this back to enclosing class
}
});
} catch (Exception e) {
e.printStackTrace();
} finally {
session.getTransaction().commit();
}
O/P: 蘇里亞
請幫我解決這個問題。或者從休眠狀態到Oracle存儲過程的任何其他方式。
我接受你的答案Raj –