hibernate调用oracle存储过程

本文介绍了一个使用Hibernate框架调用Oracle数据库存储过程的方法。通过一个具体的Java函数示例,展示了如何设置输入参数并获取输出参数的过程。

    下面是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

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值