Java代码 jdbc调用Oracle存储过程返回游标

public class JdbcUtil {
    public static Connection getConnection() throws Exception {
        Class.forName("oracle.jdbc.OracleDriver");
        Connection connection = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:orcl", "test", "oracle");
        return connection;
    }
}
建立连接
Connection connection = JdbcUtil.getConnection();
准备sql语句,?为存储过程的入参(也可有出参)
strSql="{call proc_GetJgOccupationRatio(?,?,?,?)}";
 CallableStatement callableStatement = connection.prepareCall(strSql);
 设置参数
 ......
 callableStatement.setObject(3,"0");
 ......
 4号参数为返回多对象集合的游标
   callableStatement.registerOutParameter(4, OracleTypes.CURSOR);
   执行sql语句
   callableStatement.execute();
   获取存储过程中保存在游标中的结果集
   ResultSet rs = ((OracleCallableStatement) callableStatement).getCursor(4);
   根据游标表中的字段名称获取对应值
    while (rs.next()){
            AnalysisData data = new AnalysisData();
            data.setName(rs.getString("OrgName"));
//            data.setValue(rs.getInt("CurrOccupationRatio"));
        }
        关闭连接
           rs.close();
        callableStatement.close();
        connection.close();

注:只提供大致思路步骤,未能跑通;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值