Java调用Oracle存储过程
package com.hp.test; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; public class TestOracleCrud { public static void main(String[] args) { // TODO Auto-generated method stub Connection ct = null; ResultSet rs = null; CallableStatement cs=null;//存储过程接口 try { //存储过程代码 /*create or replace procedure pro2(v_in_empno in number,v_out_ename out varchar2) is begin select ename into v_out_ename from emp where empno=v_in_empno; end;*/ //加载驱动 Class.forName("oracle.jdbc.driver.OracleDriver"); //获取连接 ct=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:oracal","scott","123456"); //调用存储过程 cs=ct.prepareCall("call pro2(?,?)"); cs.setInt(1, 7934); //给第二个问号注册 cs.registerOutParameter(2, oracle.jdbc.OracleTypes.VARCHAR); //执行 cs.execute(); } catch (Exception e) { e.printStackTrace(); } finally { try { rs.close(); ct.close(); cs.close(); } catch (Exception e) { e.printStackTrace(); } } } }