夢幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks
          有返回值的存儲過程的調用方法如下:
          public class SenderPrepareCallProcedure {
              
          public String testP(int statusWillSending, int statusNowSending, int fixedSending) {
                  String taskId 
          = null;
                  Connection connection 
          = null;
                  CallableStatement proc 
          = null;
                  
          try {
                      connection 
          = DBPool.getConnection();
                      proc 
          = connection.prepareCall("{call backtrack_taskId(?,?,?,?)}");
                      proc.setInt(
          1, statusWillSending);
                      proc.setInt(
          2, statusNowSending);
                      proc.setInt(
          3, fixedSending);
                      proc.registerOutParameter(
          4, Types.INTEGER);
                      proc.execute();
                      taskId 
          = String.valueOf(proc.getInt(4));
                      
          //System.out.println("taskId is: " + taskId);
                  }
           catch (Exception e) {
                      e.printStackTrace();
                  }
           finally {
                      
          this.freeSource(proc, connection);
                  }

                  
          if(taskId != null && !taskId.equals("0")){
                      
          return taskId;
                  }

                  
          return null;
              }


              
          private void freeSource(CallableStatement proc, Connection connection) {
                  
          if (proc != null{
                      
          try {
                          proc.close();
                      }
           catch (Exception e) {
                          e.printStackTrace();
                      }

                  }

                  
          if (connection != null{
                      
          try {
                          connection.close();
                      }
           catch (Exception e) {
                          e.printStackTrace();
                      }

                  }

              }

          }
          posted on 2007-12-18 20:03 HUIKK 閱讀(445) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 从化市| 昭觉县| 南澳县| 昌都县| 巴东县| 淮北市| 股票| 宁都县| 宝兴县| 南宁市| 康乐县| 庐江县| 建昌县| 龙海市| 盘锦市| 全州县| 秭归县| 顺昌县| 南通市| 乌什县| 阿坝县| 镇江市| 霍城县| 嘉鱼县| 彩票| 贵德县| 泌阳县| 离岛区| 崇义县| 平南县| 神池县| 莆田市| 丰都县| 洛川县| 论坛| 涞水县| 密山市| 临清市| 株洲县| 若尔盖县| 阳城县|