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

前端 未结 2 1176
Happy的楠姐
Happy的楠姐 2020-12-16 20:46

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 ?

相关标签:
2条回答
  • 2020-12-16 21:14

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

        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();          
    
    0 讨论(0)
  • 2020-12-16 21:33

    From oracle API documentation.

    ArrayDescriptor

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

    STRUCT

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

    StructDescriptor

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

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

    0 讨论(0)
提交回复
热议问题