当前位置:编程学习 > 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
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,