kooyee ‘s blog

          開源軟件, 眾人努力的結(jié)晶, 全人類的共同財富
          posts - 103, comments - 55, trackbacks - 0, articles - 66
             :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理
          import java.sql.*;

          public class StProcExample {
           
          public static void main(String[] args)
           
          throws SQLException {
          int ret_code;
          Connection conn 
          = null;
           
          try {
            
          //Load and register Oracle driver
            DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
           
          //Establish a connection

           conn 
          = DriverManager.getConnection("jdbc:oracle:thin:@training:1521:
           Oracle""oratest""oratest");
           int i_deptno = 10;
           CallableStatement pstmt 
          = conn.prepareCall("{call p_highest_
           paid_emp(?,?,?,?)}
          ");
           pstmt.setInt(1, i_deptno);
           pstmt.registerOutParameter(
          2, Types.INTEGER);
           pstmt.registerOutParameter(
          3, Types.VARCHAR);
           pstmt.registerOutParameter(
          4, Types.FLOAT);
           pstmt.executeUpdate();

           
          int o_empno = pstmt.getInt(2);
           String o_ename 
          = pstmt.getString(3);
           
          float o_sal = pstmt.getFloat(4);
           System.out.print(
          "The highest paid employee in dept "
           
          +i_deptno+" is: "+o_empno+" "+o_ename+" "+o_sal);
           pstmt.close();
           conn.close();
            }
           catch (SQLException e) {ret_code = e.getErrorCode();
             System.err.println(ret_code 
          + e.getMessage()); conn.close();}

           }

          }



          在database中調(diào)用function

          Select ValidWorkingDay(param1,prasm2) as IsWorking from dual 
          Select 
          {t '14:20:50'} as ThisDate from dual
          Select UCA_VALIDATE(
          '123456','WW','1') as Answer from dual
          或者
          SELECT ename FROM emp WHERE hiredate 
          = {t '12:00:00'}"

          Update語句
          For example, instead of using the fn keyword in embedded SQL92 syntax:

          Statement stmt 
          = conn.createStatement ();
          stmt.executeUpdate(
          "UPDATE emp SET ename = {fn CONCAT('My', 'Name')}");


          Use Oracle SQL syntax:

          stmt.executeUpdate(
          "UPDATE emp SET ename = CONCAT('My', 'Name')");


           

          Function Call Syntax

          Oracle's JDBC drivers support the following procedure and function call syntax:

          Procedure calls (without a return value):

          { call procedure_name (argument1, argument2,...) }
          
          

          Function calls (with a return value):

          { ? = call procedure_name (argument1, argument2,...) }
          當(dāng)用于call Function時,在等號= 前的?是statment的第一個parameter. 是out出來的值
          
          主站蜘蛛池模板: 龙江县| 时尚| 句容市| 邯郸县| 闵行区| 石景山区| 扎囊县| 静安区| 安陆市| 宜宾市| 鄂托克旗| 沛县| 当涂县| 南漳县| 寿光市| 都匀市| 新巴尔虎左旗| 马关县| 马龙县| 綦江县| 五指山市| 汕头市| 岱山县| 都兰县| 城市| 资源县| 漳州市| 扶风县| 东明县| 新竹市| 康定县| 辛集市| 连州市| 锡林郭勒盟| 南宫市| 商丘市| 东源县| 澎湖县| 廊坊市| 砀山县| 随州市|