hibernate调用oracle存储过程_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > hibernate调用oracle存储过程

hibernate调用oracle存储过程

 2011/1/7 8:29:43  zld406504302  http://zld406504302.javaeye.com  我要评论(0)
  • 摘要:下面是hibernate调用oracleproc的一个functionpublicInteger[]getText(StringstartTime,StringendTime,inttimeType,intspID,Stringmdn){Integer[]listCount={0,0};IntegernewBlackCount=0;IntegerblackTotalCount=0;Sessionsession=null;Connectioncon=null
  • 标签:ORA 过程 存储过程 Oracle Oracle存储过程 hibernate

?

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

发表评论
用户名: 匿名