gpt4 book ai didi

java - 如何从 java 类中调用不带参数作为表类型的过程 (2)

转载 作者:行者123 更新时间:2023-12-01 04:39:18 24 4
gpt4 key购买 nike

答案已经在这里得到回答: how to call procedure with out parameter as table type from a java class

但是我们有一个问题,代码的返回值总是“???”,trxSeq 的值返回正确。如果我们直接在数据库上调用它,代码将填充值。

我们尝试使用 varchar2、char、varchar 类型的代码。没有区别。

desc t_mam_code:
TYPE t_mam_code AS OBJECT(
code VARCHAR2(30),
trxSeq NUMBER(12)

java方法

final String typeName = "T_MAM_CODE";
final String typeTableName = "T_MAM_CODE_TAB";

// no difference, if we use Oracle Connection or java.sql.Connection
OracleConnection oracleConnection= connection.unwrap(OracleConnection.class);

// Get a description of your type (Oracle specific)
final StructDescriptor structDescriptor = StructDescriptor.createDescriptor(typeName, oracleConnection);
final ResultSetMetaData metaData = structDescriptor.getMetaData();

CallableStatement call = oracleConnection.prepareCall("{call business.getCodes(?, ?, ?, ?, ?, ?, ?)}");
// CallableStatement call = connection.prepareCall("{call business.getCodes(?, ?, ?, ?, ?, ?, ?)}");

int i = 1;
call.setString(i++, shopId);
call.setDate(i++, new java.sql.Date(consumerStamp.getTime()));
call.setInt(i++, version);
...

int out1 = i++;

call.registerOutParameter(out1, Types.ARRAY, typeTableName);
//call.registerOutParameter(out1, OracleTypes.ARRAY, typeTableName);

call.execute();

Object[] data = (Object[]) ((Array) call.getObject(out1)).getArray();
for(Object tmp : data) {
Struct row = (Struct) tmp;
// Attributes are index 1 based...
int idx = 1;
for(Object attribute : row.getAttributes()) {
System.out.println(metaData.getColumnName(idx) + " " + attribute);
++idx;
}

输出为:

CODE ??? 
TRXSEQ 200001520606 ...

输出应该是:

CODE ABC1234 
TRXSEQ 200001520606

我们通过hibernate 4.1.12使用Java 1.6、Oracle 11g、驱动程序ojdbc6-11.2.0.3.0.jar

最佳答案

感谢提示 didxga - 你让我们走上了正确的方向。我们将 orai18n.jar 添加到类路径中,现在一切正常:)

关于java - 如何从 java 类中调用不带参数作为表类型的过程 (2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16851314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com