JDBC調用預存程序,進參出參

來源:互聯網
上載者:User

標籤:輸出   conf   print   資料   cti   功能   sql   gis   params   

今天做了一個資料表拷貝的功能,用到了預存程序,就寫了一個java中用jdbc調用預存程序的代碼,成功的實現了功能,晚上跑回家記錄下

 1 Connection conn = ConnectionUtil.getConnect();//取得資料庫連接 2  3 try { 4             CallableStatement cstmt = conn.prepareCall("{call prc_patch_config(?,?,?,?)}");//根據預存程序名字調用預存程序,?代表參數 5             /** 6              * 第3個、第4個?表示輸出參數,所以在這裡要聲明輸出類型 7              */ 8             cstmt.registerOutParameter(3, Types.INTEGER);//這個參數值得是資料複製成功(0)或者失敗(1)的狀態位。所以類型INTEGER來 9             cstmt.registerOutParameter(4, Types.VARCHAR);//這個參數值是預存程序報錯資訊10             /**11              * 1、2為進參,在這個程式中1代表的是批次號,2代表的 是表名12              */13             cstmt.setString(1, (String) params.get("patchCode"));14             cstmt.setString(2, (String) params.get("tableEnName"));15             cstmt.execute();//執行預存程序16             int isSuccess = cstmt.getInt(3);//取得是否成功的資訊17             log = cstmt.getString(4);//取得報錯資訊18             19         } catch (SQLException e) {20             e.printStackTrace();21             22         }finally {23             try {24                 conn.close();//關閉串連25             } catch (SQLException e) {26                 e.printStackTrace();27             }28         }

以上就是我自己寫的調用預存程序的代碼,加了注釋,怕自己以後看不懂

JDBC調用預存程序,進參出參

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.