gpt4 book ai didi

java - Oracle 的 HikariConfig 池

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:02:51 24 4
gpt4 key购买 nike

我想为 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

最佳答案

您正在尝试将驱动程序设置为数据源类。

我就是这样做的,

        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();

关于java - Oracle 的 HikariConfig 池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46117089/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com