首页 > 代码库 > Java 调用Oracle中的存储过程
Java 调用Oracle中的存储过程
--建表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个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。