我的Spring引导应用程序中有一个方法,该方法使用Struct将对象列表传递给数据库过程。当我通过jndi从Weblogic设置数据源时,由于Struct对象被包装在weblogic包装器中,所以它破裂了。
当我说“ breaks”时,是指代码行Array array = oracleConnection.createARRAY("SCHEME_NAME.PARCEL_TAB", cpoList);
不能将Struct对象识别为有效的Struct对象,因为它已被包装。结果,应用程序在此行失败,并进入SQLException catch块。
可以关闭此包装器,但是最好保持打开状态,因为它具有以下优点:
◾监视,记录和跟踪各种情况,例如来自连接池的连接泄漏
◾容器根据数据源使用情况生成的有用指标
我看到的错误消息是:
java.sql.SQLException: Fail to convert to internal representation: weblogic.jdbc.wrapper.Struct_oracle_sql_STRUCT@187>
从此错误消息中可以看到,Struct现在被包装在weblogic包装器中。
@Override
public List<String> saveAllocation(String originalId, List<Parcel> parcels) throws SQLException {
List<String> results = null;
String result = null;
String log = null;
OracleConnection oracleConnection = (OracleConnection)jdbcTemplate.getDataSource().getConnection();
try {
OracleCallableStatement cs = (OracleCallableStatement) oracleConnection.prepareCall("{ call PACKAGE.Update(?, ?, ?, ?) }");
Struct[] cpoList = new Struct[parcels.size()];
for(int i = 0; i < parcels.size(); i++) {
Object[] obj = new Object[] { parcels.get(i).getParcel_id(), parcels.get(i).getPublicID().toUpperCase() };
Struct struct = oracleConnection.createStruct("SCHEME_NAME.PARCEL_OBJ", obj);
cpoList[i] = struct;
}
Array array = oracleConnection.createARRAY("SCHEME_NAME.PARCEL_TAB", cpoList);
cs.setString(1, originalId);
cs.setArray(2, array);
cs.registerOutParameter(3, Types.VARCHAR);
cs.registerOutParameter(4, Types.VARCHAR);
cs.executeUpdate();
log = cs.getObject(3).toString();
result = cs.getObject(4).toString();
results = new ArrayList<>();
results.add(result);
results.add(log);
} catch(SQLException e) {
//Log exception
return results;
} catch(Exception e) {
//Log exception
return results;
} finally {
if (cs != null) {
cs.close();
}
}
return results;
}
}
我的问题是:如何更改我的应用程序,以便weblogic包装器在不关闭包装器的情况下不会破坏Struct对象?