如何修复已弃用的 oracle.sql.ArrayDescriptor、oracle.sql.STRUCT 和 oracle.sql.StructDescriptor

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33347134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:03:55  来源:igfitidea点击:

How to fix deprecated oracle.sql.ArrayDescriptor, oracle.sql.STRUCT and oracle.sql.StructDescriptor

javaoraclestored-proceduresdeprecated

提问by Jay

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

我使用下面的 JDBC 代码来调用一个接受数组输入的 Oracle 存储过程。

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 code

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();

回答by Jay

Thanks UUIUI, I now removed the deprecated classes and the fixed code looks as below if anyone needs it later.

感谢 UUIUI,我现在删除了已弃用的类,如果以后有人需要,固定代码如下所示。

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

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

        struct[arrayIndex++] = connection.createStruct("R_REPORT_OBJECT", reportArray);
    }

    Array reportsArray = ((OracleConnection) connection).createOracleArray("T_REPORT_TABLE", struct);
    callableStatement.setArray("T_REPORT_IN", reportsArray);

    callableStatement.executeUpdate();          

回答by Bacteria

From oracle API documentation.

来自 oracle API 文档。

ArrayDescriptor

数组描述符

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

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

STRUCT

结构

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

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

StructDescriptor

结构描述符

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

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

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

以下是oracle API 文档中提到的弃用类的完整列表。