JAVA調用存儲過程 – JAVA編程語言程序開發技術文章

存儲過程:

create or replace procedure kelvin_pro3(kelvin_book_id in number,kelvin_book_name in varchar2, kelvin_publish_house in varchar2 ) is
begin
       insert into book values (kelvin_book_id,kelvin_book_name,kelvin_publish_house);
end;

 JAVA 代碼:

import java.sql.*;

public class test {

 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  Connection conn = null;
  CallableStatement cs = null;
  ResultSet rs =null;
  try{
   Class.forName("oracle.jdbc.driver.OracleDriver");
   conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:kelvin111G2","system","MANAGER");
   cs = conn.prepareCall("{call kelvin_pro3(?,?,?)}");
   //st = conn.createStatement();
   cs.setInt(1, 10);
   cs.setString(2, "嶽不群");
   cs.setString(3, "機械工業出版社");
   cs.execute();
  }catch(Exception e){
   e.printStackTrace();
  }finally{
    try {
     conn.close();
     cs.close();
    } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
  }
 
 }

}

作者 dongdongsdo0310

發佈留言