小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

java中調(diào)用Oracle存儲過程舉例

 流浪在北京 2010-09-22
create or replace procedure p--創(chuàng)建過程
   (v_a in number, v_b number, v_ret out number, v_temp in out number )
is  --v_temp即做輸出又做輸入,輸出就是服務(wù)器根據(jù)用戶輸入向客戶端輸出
begin
  if (v_a > v_b) then
    v_ret := v_a;
  else
    v_ret := v_b;
  end if;
  v_temp := v_temp + 1;
  end;
 
 
以下是java中的代碼
import java.sql.*;
public class TestProc {
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  
  String url = "jdbc:oracle:thin:@127.0.0.1:1521:ORCL";
  Connection conn = null;
  CallableStatement cstmt = null;
  
  try {
   Class.forName("oracle.jdbc.driver.OracleDriver");//lomboz_eclipse是我設(shè)置scott用戶的密碼而已
   conn = DriverManager.getConnection(url,"scott","lomboz_eclipse");
   System.out.println("aa");
   cstmt = conn.prepareCall("{call p(?,?,?,?)}");
   cstmt.setInt(1, 5);//輸入?yún)?shù),直接設(shè)置參數(shù)值就可以了
   cstmt.setInt(2, 6);
   cstmt.registerOutParameter(3, Types.INTEGER);   
   //輸出參數(shù),要顯示出來需注冊和打印
   cstmt.registerOutParameter(4, Types.INTEGER);
   cstmt.setInt(4, 8);   
   cstmt.execute();
   System.out.println(cstmt.getInt(3));
   System.out.println(cstmt.getInt(4));
  } catch (ClassNotFoundException e) {
   // TODO Auto-generated catch block
   System.out.println("class should be in the correct adress");
   e.printStackTrace();
  } catch (SQLException e) {
   e.printStackTrace();
  } finally {
   try {
    if(cstmt!=null) {
     cstmt.close();//這里還可以加一步,將cstmt設(shè)置為null,雖然結(jié)果一樣但效果好那么一絲絲
    }
    if(conn!=null) {
     conn.close();
    }        
   } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   
  }
 }
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多