ORACLE建立Java過程,oracle建立java

來源:互聯網
上載者:User

ORACLE建立Java過程,oracle建立java



STEP1:

CREATE OR REPLACE  JAVA SOURCE NAMED "Employee" AS
import java.sql.*;
import oracle.jdbc.*;

public class Employee{
 
  public static void getItEmps(){ 
    Connection conn = null;
    PreparedStatement pst = null;
     ResultSet rs = null;
     try{
        conn = DriverManager.getConnection("jdbc:default:connection:");
        String sql = "select * from sys.employee where e_id > 1000";
        pst = conn.prepareStatement(sql);
        rs = pst.executeQuery();
        while(rs.next()){
          System.out.println(rs.getString(1) + "\t" + rs.getString(2));
        }
    }catch(Exception e){
       System.err.println(e);
    }finally{
      try{
        rs.close();
        pst.close();
        conn.close();
      }catch(Exception e){
        System.err.println(e);
      }
    }  
  }
}



STEP2:

create or replace procedure get_it_emps AS LANGUAGE JAVA NAME 'Employee.getItEmps()';


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.