如何在ORACLE中使用JAVA存储过程
1个回答
展开全部
比如下面写的是Oracle的一个存储过程:
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;
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);
}
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;
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);
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询