Oracle有返回值的儲存過程
阿新 • • 發佈:2019-02-02
建立一個有輸入輸出的儲存過程:
<span style="font-size:18px;">CREATE OR REPLACE PROCEDURE sp_pro8
(spno IN NUMBER,spName OUT VARCHAR2)
IS
BEGIN
SELECT ename INTO spName FROM emp WHERE empno=spno;
END;</span>
Java程式碼:
package com.wfc.test; import java.sql.*; public class Test2{ public static void main(String[] args){ Connection ct=null; CallableStatement cs=null; try{ Class.forName("oracle.jdbc.driver.OracleDriver"); ct = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl","scott","tiger"); cs = ct.prepareCall("{call sp_pro8(?,?)}"); //("{call聽sp_pro8(?,?)}"); cs.setInt(1,7788); cs.registerOutParameter(2,oracle.jdbc.OracleTypes.VARCHAR); //5.鎵ц cs.execute(); String name=cs.getString(2); System.out.println("7788的名字"+name); } catch(Exception e){ e.printStackTrace(); } finally{ //6.鍏抽棴鍚勪釜鎵撳紑鐨勮祫婧� try { cs.close(); ct.close(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }