存储过程是在大型数据库系统中,一组为了完成特定功能的SQL 语句集,存储在数据库中,经过第一次编译后再次调用不需要再次编译,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。今天,我们就开始学习java中调用oracle的存储过程。
java中调用oracle的存储过程
项目结构如下:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARQAAAC1CAIAAAARJZfRAAAdXUlEQVR4nO2d+VsT577A83fcH+4P97nXe+6x5/ZaBSltrdW2tL09Wnue3moX19P0YD2nPe4rFGUJuEUBF0RFAQ3IoiIxoIgouEAAQUBMWBMEspKELBMW5/4wYTI7Q0hIJn4/z/so8877vvOGZz6870zm/Y4I9R9Gs+Vsbmn6hcL0C4XZeaWjdgdx75B59PuUUj8eDgCCi8iPbUmzrg6/6jbp+o26vs72Z+lnc4l7Bwy25Ttz2eoCgODwjzw6velgSvqL6kOOruPurqPO9hT9wwNnU/fs2J+2Y3/awZR0nd4UQvLIxaJoqTrYvQCEjn/kOZiSbhusQq0PGNKka3LcOTJiZZdHLY0W4YjlfukRJyAP4A/8I8+u+AzUfIc5oSh2qcMpz9S5rJZGz8F5DfIA/oCvPNXV1RKJhG3vtv3nUf0N5vR6cvnO3Apld/LV2g1HbjLVJsgzNyc2yAP4A17yVFVVzZ8/f968eWwFftl+CX11BUuT2vw7pXm/J8p+3Zb767bcjhevbj5WLd12+dPd+U87X5XcaKbVZpRHLY0WieVysUg0daLLxcyTO2/+VCv0HEr1qR3YQfBeeH7mOjRIB+BMLw9mzurVqznk+VGcg/Zno/3ZLtX5Awdl6dfbb/RPYumWZtKEvMaKdehcP28tptVmnLZhF0K4JHIx8cSVi6d2kfM9OXgGLoS3AqkOuzzk4vQGAWA6eXBz1qxZwyHPVz9cQrtPOF+c/G1PweGS7sIXbno699D403a59pWVVpt4w4DlNKVOtKb20idg5AHG0yKlGL7JNfJwNggA3PIQzeGWJ+bbfGdr6s9brx3KV19W2ukpXaH77tfK/gEbU23StI2QyS1PtFTNIg+9sVnKA7oAT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eTE+OTkRFlZGUN96tXI1LmMn9OUAqzTtqlN+uUNOYftgN4t0tgDq8eFgSDl+dOmDGIaGBhQPKhPuVAiuVB6t7Yh40r56fzrExPjExPjN27cYKjPcC5HS9V+lYd8ycMqj1oaLaK3DfIIA0HKg6Loj1c3ElOhojav7D6WhoeHM3JLsFvYxcXFTLVp0zZqsF7itI16gjPFSCCWl0unRCRUiiblMVlKaA3kEQZCleftU/9HTCcvF+Ep/XJx4qlL2FdARUVFLA1Md8OAeP0vJY88jDESvHMvhlsO1IsfaqA5kUgkihaLYeQRFoKU59G2d+nJ6bC7HA6X04m4XG4EGXMjY2Pu8+fPz6DdOTtpwY6wQJDy1Ijf6jjyBTHViN9y2EfJ/rjG3IhUKuXf7Jx97w8PGIQHgpTnzup/pSf76CjdH46QcSQ8M6zAjwZzdiAg8AhSHoy9/Ah2N4GwRcDyAEBwAXkAwEdAHgDwEZAHAHzEn/IYzZazuaXpFwrTLxRm55WO2h3EvUPm0e9TSv14OAAILv8Pr7SMHbXnnewAAAAASUVORK5CYII=" alt="" />
一、 在数据库创建存储过程的脚本,如果使用的是本地的oracle数据库,则需要开启服务:OracleOraDb11g_home1TNSListener和OracleServiceORCL。
存储过程实现:输入用户的工号,输出用户的名字、薪水和工作。
create or replace procedure queryempinfo(eno in number,
pename out varchar2,
psal out number,
pjob out varchar2)
as
begin
--得到该员工的姓名 月薪和职位
select ename, sal, job into pename, psal, pjob from emp where empno = eno;
end;
二、 在项目中引入oracle的jdbc的jar包,Procedure的代码如下:
package com.tomhu.procedure; import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException; import oracle.jdbc.OracleTypes; public class Procedure { private Connection conn;
private CallableStatement stat;
private ResultSet rs; String url = "jdbc:oracle:thin:@127.0.0.1:1521:orcl";
String driverName = "oracle.jdbc.driver.OracleDriver";
String username = "scott";
String password = "******";
String sql = "call queryempinfo(?,?,?,?)"; // 调用存储过程
public void callProcedure() {
try {
Class.forName(driverName);
conn = DriverManager.getConnection(url, username, password);
stat = conn.prepareCall(sql); // 一个输入参数和三个输出参数
stat.setInt(1, 7566);
stat.registerOutParameter(2, OracleTypes.VARCHAR);
stat.registerOutParameter(3, OracleTypes.NUMBER);
stat.registerOutParameter(4, OracleTypes.VARCHAR);
stat.execute(); String name = stat.getString(2);
int sal = stat.getInt(3);
String job = stat.getString(4); System.out.println("name: " + name + ", sal: " + sal + ", job: " + job); } catch (Exception e) {
e.printStackTrace();
} finally {
close(conn, stat, rs);
}
} // 关闭连接
public void close(Connection conn, CallableStatement stat, ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
rs = null;
}
}
if (stat != null) {
try {
stat.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
stat = null; }
}
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
conn = null;
}
}
} public static void main(String[] args) {
new Procedure().callProcedure();
}
}
三、 得到的输出结果:
name: JONES, sal: 2975, job: MANAGER
友情链接
jdbc的jar包: http://pan.baidu.com/s/1jHUTPRo
http://www.cnblogs.com/huhx/p/JavaProcedure.html