I using Hikari Pool and OracleCallableStatement:
My datasource:
<bean id="myDataSource" class="com.zaxxer.hikari.HikariDataSource">
<property name="jdbcUrl" value="${my.oracle.url}"/>
<property name="driverClassName" value="oracle.jdbc.pool.OracleDataSource"/>
<property name="username" value="${my.oracle.user}"/>
<property name="password" value="${my.oracle.password}"/>
</bean>
And I try make a request to Oracle:
public List getProducts(int numbersMonths, Long initServiceId,
List<Long> serviceIds) throws SQLException {
Connection cnn = null;
OracleCallableStatement stm = null;
ResultSet rs = null;
List<ProductLink> res = new ArrayList<>();
final String sql = sqlCust(sqlProducts);
try {
cnn = custDataSource.getConnection();
stm = (OracleCallableStatement) cnn.prepareCall(sql);
stm.setPlsqlIndexTable(1, serviceIds.toArray(), serviceIds.size(), serviceIds.size(), OracleTypes.BIGINT, 0);
stm.registerOutParameter(2, OracleTypes.CURSOR);
stm.setLong(3, initServiceId);
stm.setInt(4, numbersMonths);
stm.execute();
rs = stm.getCursor(2);
// do stuff
} catch (SQLException ex) {
DbUtils.closeQuietly(cnn, stm, rs);
throw ex;
} finally {
DbUtils.closeQuietly(cnn, stm, rs);
}
But I have error om this line: stm = (OracleCallableStatement) cnn.prepareCall(sql);
java.lang.ClassCastException: com.zaxxer.hikari.pool.HikariProxyCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement
Also I have a error:
Failed to create instance of driver class oracle.jdbc.pool.OracleDataSource, trying jdbcUrl resolution
java.lang.ClassCastException: oracle.jdbc.pool.OracleDataSource cannot be cast to java.sql.Driver
on this line: cnn = custDataSource.getConnection();
What is wrong? Why I getting this errors?
In fact, since you are using a connection pool, the CallableStatement implementation is not from the driver, but from that connection pool instead.
Either you should find a way to access the core implementation (which I think is risky), or you should try to use the CallableStatement only, and not depend on Oracle implementation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With