java 调用oracle function

 

今天java小生贴出 java调用oracle  function  的方法

  List<WhiteBlackListInfo> whiteList = new ArrayList<WhiteBlackListInfo>();
  List<List<String>> strList = new ArrayList<List<String>>();

  Integer dataCount = 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 GETWHITELISTCOUNTBYSP(?,?,?,?,?,?,?)}");
   cstmt.setString(2, startTime);
   cstmt.setString(3, endTime);
   cstmt.setInt(4, timeType);
   cstmt.setInt(5, spID);
   cstmt.setInt(6, pageSize);
   cstmt.setInt(7, currentPage);
   cstmt.registerOutParameter(1, Types.ARRAY, "WHITE_LIST_TYPE_ARRAY");//type
   cstmt.registerOutParameter(8, java.sql.Types.INTEGER);
   cstmt.executeUpdate();
   dataCount = cstmt.getInt(8);
   oracle.sql.ARRAY arry = (ARRAY) cstmt.getArray(1);
   Array array = (Array) cstmt.getArray(1);

   if (arry != null && arry.length() > 0) {
    Object[] items = (Object[]) array.getArray();
    Object obj;
    for (int i = 0; i < items.length; i++) {
     obj = items[i];
     Struct a = (Struct) obj;
     WhiteBlackListInfo wbInfo = new WhiteBlackListInfo();
     wbInfo.setSpID(Integer.parseInt(a.getAttributes()[0]
       .toString()));
     wbInfo.setSpName(String.valueOf(a.getAttributes()[1]));
     wbInfo.setSpCode(String.valueOf(a.getAttributes()[2]));
     wbInfo.setSpTypeid(Integer.parseInt(a.getAttributes()[3]
       .toString()));
     wbInfo.setSpStatusid(Integer.parseInt(a.getAttributes()[4]
       .toString()));
     wbInfo.setWhiteListCount(Integer
       .parseInt(a.getAttributes()[5].toString()));
     whiteList.add(wbInfo);
    }
   }
   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 {
   ;
  }
  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值