我从 Oracle 默认数据源切换到 HikariCP。在一段代码中,我将自定义 Oracle 类型传递给存储的参数,并将 java.sql.Connection
转换为 oracle.jdbc.OracleConnection
。
try(OracleConnection connection = (OracleConnection) dbConnect.getConnection()) {
try(CallableStatement callableStatement = connection.prepareCall("{? = call pkg_applications.add_application(?,?,?)}")) {
callableStatement.registerOutParameter(1, Types.VARCHAR);
callableStatement.setString(2, form.getPolicyNumber());
callableStatement.setString(3, form.getPolicyStart());
Object[][] uploads = new Object[wrappers.size()][];
for(int i=0; i<wrappers.size(); i++) {
uploads[i] = new Object[4];
uploads[i][0] = wrappers.get(i).getName();
uploads[i][1] = wrappers.get(i).getFile().getContentType();
uploads[i][2] = wrappers.get(i).getFile().getSize();
uploads[i][3] = wrappers.get(i).getLocation();
}
callableStatement.setArray(4, connection.createARRAY("T_UPLOAD_FILE_TABLE", uploads));
callableStatement.execute();
int applicationId = callableStatement.getInt(1);
operationResponse.setData(applicationId);
operationResponse.setCode(ResultCode.OK);
}
}
catch(Exception e) {
log.error(e.getMessage(), e);
}
我得到一个 java.lang.ClassCastException - com.zaxxer.hikari.pool.HikariProxyConnection cannot be cast to oracle.jdbc.OracleConnection
。
如何使用 HikariCP 将 Oracle 自定义类型传递给存储过程?
最佳答案
您从池中获得的是代理连接。 要访问底层 Oracle 连接,您应该将 unwrap() 与 isWrapperFor() 结合使用:
try (Connection hikariCon = dbConnect.getConnection()) {
if (hikariCon.isWrapperFor(OracleConnection.class)) {
OracleConnection connection = hikariCon.unwrap(OracleConnection.class);
:
:
}
但是,在您的示例中,OracleConnection 特定于哪个方法?你可能根本不需要转换!
关于java - HikariCP 通过 Oracle 自定义类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40087536/