com.zaxxer.hikari.pool.HikariPool$PoolInitializationException:尝试使用 Redshift 设置 HikraCP 时无法初始化池
Posted
技术标签:
【中文标题】com.zaxxer.hikari.pool.HikariPool$PoolInitializationException:尝试使用 Redshift 设置 HikraCP 时无法初始化池【英文标题】:com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool when trying to setup HikraCP with Redshift 【发布时间】:2016-07-15 12:33:48 【问题描述】:我正在尝试使用 HikariCP 和 AWS Redshift 设置 JDBC 连接池,如下所示:
public class RedshiftConnector
private static HikariDataSource dataSource;
private static int poolSize = 5;
public static void init() throws SQLException
dataSource = new HikariDataSource();
dataSource.setDataSource(new com.amazon.redshift.jdbc42.DataSource());
dataSource.setJdbcUrl(Parameters.REDSHIFT_DB_URL);
dataSource.setUsername(Parameters.REDSHIFT_DB_USERNAME);
dataSource.setPassword(Parameters.REDSHIFT_DB_PASSWORD);
dataSource.setLogWriter(new PrintWriter(System.out));
dataSource.setMaximumPoolSize(poolSize);
public static synchronized Connection getConnection()
return dataSource.getConnection();
public static void close()
dataSource.close();
我已经在类路径中添加了 Redshift Driver 的 JAR!
现在的问题是当我打电话给RedshiftConnector.getConnection()
时,我收到以下错误:
[com.zaxxer.hikari.pool.HikariPool$PoolInitializationException: Failed to initialize pool: Error creating Driver, Driver class name incorrect.] with root cause
java.lang.ClassCastException: com.amazon.redshift.jdbc42.Driver cannot be cast to com.amazon.dsi.core.interfaces.IDriver
at com.amazon.dsi.core.impl.DSIDriverFactory.createDriver(Unknown Source)
at com.amazon.jdbc.common.AbstractDataSource.doInitialize(Unknown Source)
at com.amazon.jdbc.common.AbstractDataSource.getSimbaConnection(Unknown Source)
at com.amazon.jdbc.common.AbstractDataSource.getConnection(Unknown Source)
at com.amazon.jdbc.common.AbstractDataSource.getConnection(Unknown Source)
at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:316)
at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:506)
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:118)
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:94)
谢谢
【问题讨论】:
看起来像是该 redshift 驱动程序中的错误(特别是java.lang.ClassCastException: com.amazon.redshift.jdbc42.Driver cannot be cast to com.amazon.dsi.core.interfaces.IDriver
),或者您的类路径中的库版本不一致。
【参考方案1】:
我找到了解决办法:
而不是使用 setDataSource():
dataSource.setDataSource(new com.amazon.redshift.jdbc42.DataSource());
我们必须使用 setDriverClassName() 并与 AWS Redshift 完美配合:
dataSource.setDriverClassName("com.amazon.redshift.jdbc42.Driver");
谢谢
【讨论】:
还需要提一下,driverClassName 需要jdbcUrl,setDataSource 不需要jdbcUrl以上是关于com.zaxxer.hikari.pool.HikariPool$PoolInitializationException:尝试使用 Redshift 设置 HikraCP 时无法初始化池的主要内容,如果未能解决你的问题,请参考以下文章