适用于Oracle的HikariConfig池

时间:2017-09-08 12:56:10

标签: java oracle jdbc connection-pooling hikaricp

我想为Oracle配置HikariConfig池:

Properties props = new Properties();
        props.setProperty("dataSourceClassName",     "oracle.jdbc.driver.OracleDriver");
        props.setProperty("dataSource.user",         bundle.getString("db.user"));
        props.setProperty("dataSource.password",     bundle.getString("db.password"));
        props.setProperty("dataSource.databaseName", "xe");

        config = new HikariConfig(props);
        ds = new HikariDataSource(config);

但是我收到了这个错误

Exception in thread "main" java.lang.RuntimeException: java.lang.ClassCastException: Cannot cast oracle.jdbc.driver.OracleDriver to javax.sql.DataSource
    at com.zaxxer.hikari.util.UtilityElf.createInstance(UtilityElf.java:93)
    at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:339)
    at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:118)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:106)
    at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:72)
    at 

1 个答案:

答案 0 :(得分:2)

您正在尝试将驱动程序设置为datasouce类。

我就是这样做的,

        HikariConfig config = new HikariConfig();
        config.setMaximumPoolSize(10);
        config.setMinimumIdle(5);
        config.setDriverClassName("org.hsqldb.jdbc.JDBCDriver");
        config.setJdbcUrl("jdbc:hsqldb:hsql://localhost/");
        config.addDataSourceProperty("user", "SA");
        config.addDataSourceProperty("password", "");

        HikariDataSource ds = new HikariDataSource(config);
        System.out.print("Data source created");
        Connection conn = ds.getConnection();