下面是hibernate调用oracle proc 的一个function
public Integer[] getText(String startTime, String endTime,
int timeType, int spID ,String mdn) {
Integer[] listCount = {0,0};
Integer newBlackCount = 0 ;
Integer blackTotalCount = 0 ;
Session session = null;
Connection con = null;
CallableStatement cstmt = null;
Transaction tr = null;
try {
session = getHibernateTemplate().getSessionFactory().openSession();
tr = session.beginTransaction();
con = session.connection();
cstmt = con.prepareCall("{call getBlackListCount(?,?,?,?,?,?,?)}");
cstmt.setString(1, startTime);
cstmt.setString(2, endTime);
cstmt.setInt(3, timeType);
cstmt.setInt(4, spID);
cstmt.registerOutParameter(5, java.sql.Types.INTEGER); //设置返回参数类型
cstmt.registerOutParameter(6, java.sql.Types.INTEGER);
cstmt.setString(7, mdn);
cstmt.executeUpdate();
newBlackCount = cstmt.getInt(5);//获取返回参数
blackTotalCount = cstmt.getInt(6);
if(newBlackCount > 0 ){
listCount[0] = newBlackCount ;
}
if(blackTotalCount > 0 ){
listCount[1] = blackTotalCount ;
}
tr.commit();
} catch (HibernateException e) {
e.printStackTrace();
tr.rollback();
log.error(e.getMessage());
} catch (SQLException e) {
e.printStackTrace();
tr.rollback();
log.error(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
log.error("error", e);
} finally {
;
}
return listCount;
}
java小生 与大家共同进步 希望多多指点!
http://www.1diaocha.com/user/Register.aspx?account=soqian
本文介绍了一个使用Hibernate框架调用Oracle数据库存储过程的方法。通过一个具体的Java函数示例,展示了如何设置输入参数并获取输出参数的过程。
1060

被折叠的 条评论
为什么被折叠?



