1

答案接缝已经在这里得到回答: 如何从java类调用带有out参数的过程作为表类型

但是我们有问题,返回值 vor 代码总是“???”,正确返回 trxSeq 的值。如果我们直接在 db 上调用它,代码就会被值填充。

我们尝试了 varchar2、char、varchar 类型的代码。没有不同。

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

方法

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

4

1 回答 1

0

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

于 2013-06-03T06:01:54.503 回答