夢幻之旅

          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 閱讀(443) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 乌什县| 遵义市| 始兴县| 灵山县| 张家港市| 博客| 姚安县| 平南县| 晋中市| 大冶市| 临澧县| 青海省| 陈巴尔虎旗| 桑植县| 保康县| 英山县| 清远市| 宜宾市| 唐山市| 综艺| 文昌市| 奉节县| 托克逊县| 防城港市| 色达县| 高邮市| 化隆| 揭西县| 曲周县| 泸溪县| 靖远县| 宽甸| 高唐县| 曲沃县| 灵璧县| 芮城县| 梁平县| 富宁县| 吕梁市| 开原市| 嘉义县|