如何修复已弃用的 oracle.sql.ArrayDescriptor、oracle.sql.STRUCT 和 oracle.sql.StructDescriptor [英] How to fix deprecated oracle.sql.ArrayDescriptor, oracle.sql.STRUCT and oracle.sql.StructDescriptor
问题描述
我使用下面的 JDBC 代码来调用一个接受数组输入的 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.
使用工厂方法 OracleConnection.createOracleArray 直接创建 java.sql.Array 的实例.
Use factory method OracleConnection.createOracleArray to create an instance of java.sql.Array directly.
使用 java.sql.Struct 接口进行声明,而不是使用具体类 oracle.sql.STRUCT.
Use java.sql.Struct interface for declaration instead of using concrete class oracle.sql.STRUCT.
使用工厂方法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屋!