[英]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的? 你可能根本不需要施展!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.