HikariCP with Oracle com.zaxxer.hikari.pool.HikariProxyCallableStatement 无法转换为 oracle.jdbc.OracleCallableStatement

HikariCP with Oracle com.zaxxer.hikari.pool.HikariProxyCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement

我使用 Hikari PoolOracleCallableStatement:

我的数据源:

<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>

然后我尝试向 Oracle 发出请求: public 列出 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);
        }

但是我在这一行有错误:stm = (OracleCallableStatement) cnn.prepareCall(sql);

java.lang.ClassCastException: com.zaxxer.hikari.pool.HikariProxyCallableStatement cannot be cast to oracle.jdbc.OracleCallableStatement

我也有一个错误:

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

这一行:cnn = custDataSource.getConnection();

怎么了?为什么我会收到此错误?

改用CallableStatement

The interface used to execute SQL stored procedures. The JDBC API provides a stored procedure SQL escape syntax that allows stored procedures to be called in a standard way for all RDBMSs.

这被prepareCall方法使用

Creates a CallableStatement object

事实上,由于您使用的是连接池,因此 CallableStatement 实现不是来自驱动程序,而是来自连接池。

要么你应该找到一种方法来访问 core 实现(我认为这是有风险的),或者你应该尝试只使用 CallableStatement,而不是取决于 Oracle 实施。

尝试替换行

            stm = (OracleCallableStatement) cnn.prepareCall(sql);

            stm = cnn.prepareCall(sql).unwrap(OracleCallableStatement.class);