如何在ORACLE中使用JAVA存储过程
发布网友
发布时间:2022-04-20 11:16
我来回答
共1个回答
热心网友
时间:2022-04-07 21:07
比如下面写的是Oracle的一个存储过程:
create or replace procere 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;
Java调用Oracle的存储过程
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);
}