Java调用DB的存储过程

2015/12/7
 使用数据库存储过程的java代码:
   try {
            con = (Connection) DBProxy.getConnection(null);
            cStm = con.prepareCall("{call web_show_proc("+("sp".equalsIgnoreCase(showPara[0])?"true":"false")+"," + lmdm + "," + showPara[1] + ")}");
            boolean hadResults = cStm.execute();
            if (hadResults) {
                rs = cStm.getResultSet();
                if (rs.next()) {
//                    nrTemplate = nrTemplate.replaceAll("#bt#", rs.getString("BT")).replaceAll("#fbsj#", rs.getString("FBSJ"))
//                            .replaceAll("#gjly#", rs.getString("LYZ")).replaceAll("#xxnr#", rs.getString("NR").replaceAll("\\^~\\^", ""));
//                    nr.append(nrTemplate);
                   
                }
            }
            String itemContent = null;
            hadResults = cStm.getMoreResults();
            if (hadResults) {
  //上一篇文章
                rs = cStm.getResultSet();
                while (rs.next()) {
                    itemContent = rs.getString("item");
                    itemContent = itemContent.replaceAll("#lm#", webLmAb.get(lm)).replaceAll("#previous#", "上一篇");
                    neighbor.append(itemContent);
                }
            }
            hadResults = cStm.getMoreResults();
            if (hadResults) {
                //下一篇文章
                rs = cStm.getResultSet();
                while (rs.next()) {
                    itemContent = rs.getString("item");
                    itemContent = itemContent.replaceAll("#lm#", webLmAb.get(lm)).replaceAll("#next#", "下一篇");
                    neighbor.append(itemContent);
                }
            }
        } catch (Exception e) {
            Logger.logger.error("查询栏目 " + lmdm + " 的信息" + "时,抛错:", e);
        } finally {
            DBProxy.closeDBObject(new Object[]{rs, cStm, con});
        }

posted @ 2017-07-15 10:29  乐在克里特  阅读(255)  评论(0编辑  收藏  举报