?
??? 下面是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小生 与大家共同进步 希望多多指点!