0bj*_*3ct 4 java oracle datasource jdbc hikaricp
我从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);
}
Run Code Online (Sandbox Code Playgroud)
我得到了java.lang.ClassCastException - com.zaxxer.hikari.pool.HikariProxyConnection cannot be cast to oracle.jdbc.OracleConnection.
如何使用HikariCP将Oracle自定义类型传递给存储过程?
Nit*_*tin 13
你从池中获得的是代理连接.要访问底层Oracle连接,您应该将unwrap()与isWrapperFor()一起使用:
try (Connection hikariCon = dbConnect.getConnection()) {
if (hikariCon.isWrapperFor(OracleConnection.class)) {
OracleConnection connection = hikariCon.unwrap(OracleConnection.class);
:
:
}
Run Code Online (Sandbox Code Playgroud)
但是,在您的示例中,哪种方法是特定于OracleConnection的?你可能根本不需要施展!
| 归档时间: |
|
| 查看次数: |
3083 次 |
| 最近记录: |