Oracle pl/sql编程 23---怎么用java调用oracle函数

来源:互联网 时间:1970-01-01

 写一个函数

<span style="font-size:24px;"> create or replace function fun1(in_empno in number) return varchar2 is v_outname varchar2(32); begin select ename into v_outname from emp where emp.empno=in_empno; return v_outname; end; </span>


Java程序


public static void main(String[] args) { Connection conn=null; CallableStatement callable=null; //加载驱动 try { Class.forName("oracle.jdbc.driver.OracleDriver"); //获得连接 conn=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:orcl", "scott", "m123"); //第一个问号表示返回值第二个问号表示传入参数 callable=conn.prepareCall("{?=call fun1(?)}"); callable.setInt(2, 9527); callable.registerOutParameter(1, Types.VARCHAR); callable.execute(); System.out.println(callable.getString(1)); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }




相关阅读:
Top