如何修复不建议使用的oracle.sql.ArrayDescriptor,oracle.sql.STRUCT和oracle.sql.StructDescriptor [英] How to fix deprecated oracle.sql.ArrayDescriptor, oracle.sql.STRUCT and oracle.sql.StructDescriptor

查看:653
本文介绍了如何修复不建议使用的oracle.sql.ArrayDescriptor,oracle.sql.STRUCT和oracle.sql.StructDescriptor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的JDBC代码来调用需要Array输入的Oracle存储过程.

I use the below JDBC code to call an Oracle stored procedure which takes an Array input.

但是不推荐使用以下三个类.如何替换呢?

But the the below three classes are deprecated. How to replace this ?

import oracle.sql.ArrayDescriptor;
import oracle.sql.STRUCT;
import oracle.sql.StructDescriptor;

Java代码

        Object[] reportArray = new Object[3]; 
        STRUCT[] struct = new STRUCT[reports.size()];

        ArrayDescriptor arrayDescriptor = new ArrayDescriptor(new SQLName("T_REPORT_TABLE", (OracleConnection) connection), connection);
        StructDescriptor structDescriptor = StructDescriptor.createDescriptor("R_REPORT_OBJECT", connection);

        int arrayIndex = 0;
        for (Report data : reports) {
            reportArray[0] = data.getXXX();
            reportArray[1] = data.getYYY();
            reportArray[2] = data.getZZZ();

            struct[arrayIndex++] = new STRUCT(structDescriptor, connection, reportArray);
        }

        oracle.sql.ARRAY reportsArray = new oracle.sql.ARRAY(arrayDescriptor, connection, struct);
        callableStatement.setArray("T_REPORT_IN", reportsArray);

        callableStatement.executeUpdate();

推荐答案

来自oracle API文档.

From oracle API documentation.

ArrayDescriptor

ArrayDescriptor

使用工厂方法OracleConnection.createOracleArray直接创建java.sql.Array的实例.

Use factory method OracleConnection.createOracleArray to create an instance of java.sql.Array directly.

结构

STRUCT

使用java.sql.Struct接口进行声明,而不要使用具体的类oracle.sql.STRUCT.

Use java.sql.Struct interface for declaration instead of using concrete class oracle.sql.STRUCT.

StructDescriptor

StructDescriptor

使用工厂方法Connection.createStruct直接创建java.sql.Struct的实例.

Use factory method Connection.createStruct to create an instance of java.sql.Struct directly.

以下是不推荐使用的类的完整列表oracle API文档中提到过.

Here are the full list of Deprecated Classes mentioned in the oracle API documentation.

这篇关于如何修复不建议使用的oracle.sql.ArrayDescriptor,oracle.sql.STRUCT和oracle.sql.StructDescriptor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆