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

I am using the JDBC code below to call an Oracle stored procedure that accepts array input.

But the next three classes are out of date. How to replace it?

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

Java code

        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();
+4
source share
2 answers

From the oracle API documentation.

ArrayDescriptor

Use the factory method OracleConnection.createOracleArray to instantiate java.sql.Array directly.

STRUCT

Use the java.sql.Struct interface to declare instead of using the specific oracle.sql.STRUCT class.

StructDescriptor

factory Connection.createStruct java.sql.Struct.

, API oracle.

+8

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

Source: https://habr.com/ru/post/1613204/


All Articles