java调用oracle有返回值的函数



create or replace function myfun1(v_ename varchar2) return
number is v_sal number(7,2);
begin
  select sal*12+nvl(comm,0)*12 into v_sal from pme where ename=v_ename;
  return v_sal;
end;


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import  java.sql.*;
  
public  class  Testproc {
  
     public  static  void  main(String[] args) {
         try {
             Class.forName( "oracle.jdbc.driver.OracleDriver" );
             Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@localhost:1521:myora1" "scott" "tiger" );
             CallableStatement c = conn.prepareCall( "{?=call myfun1(?)}" );
             c.registerOutParameter( 1 , Types.VARCHAR);
             c.setString( 2 "SCOTT" );
             c.execute(); 
             String s = c.getString( 1 );
             System.out.println(s);
             c.close(); 
             conn.close();
         } catch (ClassNotFoundException e){
             e.printStackTrace();
         } catch (SQLException e){
             e.printStackTrace();
         }
     }
}

猜你喜欢

转载自xumiao900.iteye.com/blog/1724775
今日推荐