HikariCP 通过 Oracle 自定义类型
HikariCP pass Oracle custom type
我从 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 特定于哪个方法?您可能根本不需要投射!
我从 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 特定于哪个方法?您可能根本不需要投射!