OracleCallableStatement

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发出请求:
 公共列表getProducts(int numberMonths,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实现不是来自驱动程序,而是来自该连接池。

您应该找到一种访问核心实现的方法(我认为这是有风险的),或者您应该尝试仅使用CallableStatement而不依赖于Oracle实现。

07-25 20:12