Oracle使⽤jdbc调⽤带游标参数的存储过程package com.jckb.procedure;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import oracle.jdbc.OracleCallableStatement;
public class MainTest3  {
/**
* 使⽤jdbc调⽤带游标参数的存储过程
create or replace PACKAGE PACKAGE1 AS
--定义游标类型
type empCursor is ref cursor;
--定义存储过程使⽤游标
oracle游标的使用procedure findEmpInfoByDept(mydeptno in number,empInfo out empCursor);
END PACKAGE1;
-------------------
create or replace PACKAGE BODY PACKAGE1 AS
procedure findEmpInfoByDept(mydeptno in number,empInfo out empCursor) AS
BEGIN
-- 根据指定的部门编号员⼯信息赋值隔⽇输出型变量游标
open empInfo for select * from emp where deptno=mydeptno;
--此处不能关闭游标
END findEmpInfoByDept;
END PACKAGE1;
* */
public static void main(String[] args) throws Exception{
Class.forName("oracle.jdbc.OracleDriver");
Connection connection = Connection("jdbc:oracle:thin:@localhost:1521:orcl", "scott", "tiger");
CallableStatement callableStatement = connection.prepareCall("{call PACKAGE1.findEmpInfoByDept(?,?)}");
callableStatement.setInt(1, 10);
//获取值
ResultSet resultSet = ((OracleCallableStatement)callableStatement).getCursor(2);
()){
int empno = Int(1);
String ename = String(2);
String job = String(3);
System.out.println("编号:" + empno + " ⽤户:" + ename + " ⼯作:" + job);
}
resultSet.close();
callableStatement.close();
connection.close();
}
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。