Java 調用Oracle中的預存程序

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   java   for   

--建表SQL> create table TBook(bookId number(8),bookName varchar2(50),publishHouse varchar2(50));--編寫過程--in:輸入參數;out:輸出參數SQL> create or replace procedure sp_pro7(spBookId in number,spName in Varchar2,spPublishHost in varchar2) isbegin  insert into TBook values(spBookId,spName,spPublishHost);end;
--在Java中調用(工程中要載入odbcDriver)
 1 package oracle; 2  3 import java.sql.CallableStatement; 4 import java.sql.Connection; 5 import java.sql.DriverManager; 6 import java.sql.SQLException; 7  8  9 10 //調用一個無傳回值的過程11 public class Test01 {12 13     public static void main(String[] args) {14         // TODO Auto-generated method stub15         Connection conn = null;16         CallableStatement cs = null;17         try {18             //1.載入驅動19             Class.forName("oracle.jdbc.driver.OracleDriver");20             21             //2.串連22             String url = "jdbc:oracle:thin:@127.0.0.1:1521:ORACLE12C";23             String userName = "sys as SYSDBA";24             String password = "fairy6280";25             conn = DriverManager.getConnection(url,userName,password);26             //3.建立CallableStatement27             String sql = "{call sp_pro7(?,?,?)}";28             cs = conn.prepareCall(sql);29             //給‘?‘賦值30             cs.setInt(1, 1001);31             cs.setString(2, "The History of the Three Kingdoms");32             cs.setString(3, "People‘s Publishing House");33             //執行34             cs.execute();35             36         } catch (Exception e) {37             // TODO Auto-generated catch block38             e.printStackTrace();39         }40         finally{41             //關閉42             try {43                 cs.close();44                 conn.close();45             } catch (SQLException e) {46                 // TODO Auto-generated catch block47                 e.printStackTrace();48             }49         }50     }51 52 }

Java 調用Oracle中的預存程序

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.