我试图将HikariCP与PostgreSQL一起使用,但是它不起作用。它引发异常:
WARN [2014-10-24 14:38:54,195] com.zaxxer.hikari.pool.HikariPool: Exception during keep alive check, that means the connection must be dead. ! org.postgresql.util.PSQLException: Method org.postgresql.jdbc4.Jdbc4Statement.setQueryTimeout(int) is not yet implemented. ! at org.postgresql.Driver.notImplemented(Driver.java:753) ~[postgresql-9.0-801.jdbc4.jar:na] ! at org.postgresql.jdbc2.AbstractJdbc2Statement.setQueryTimeout(AbstractJdbc2Statement.java:656) ~[postgresql-9.0-801.jdbc4.jar:na] ! at com.zaxxer.hikari.pool.HikariPool.isConnectionAlive(HikariPool.java:473) [HikariCP-java6-2.1.0.jar:na] ! at com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:178) [HikariCP-java6-2.1.0.jar:na] ! at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:94) [HikariCP-java6-2.1.0.jar:na]
我尝试了所有可能的驱动程序版本(包括org.postgresql:postgresql:9.3-1102-jdbc41)-没有任何帮助。有人在PostgreSQL中使用它吗?
org.postgresql:postgresql:9.3-1102-jdbc41
这是我的配置文件:
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig"> <property name="connectionTestQuery" value="SELECT 1" /> <property name="dataSourceClassName" value="org.postgresql.ds.PGSimpleDataSource" /> <property name="maximumPoolSize" value="${jdbc.maximumPoolSize:20}" /> <property name="idleTimeout" value="${jdbc.idleTimeout:600000}" /> <property name="dataSourceProperties"> <props> <prop key="databaseName">vidsearch_test</prop> <prop key="user">${hibernate.connection.username}</prop> <prop key="password">${hibernate.connection.password}</prop> </props> </property> </bean> <bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"> <constructor-arg ref="hikariConfig"/> </bean>
不要使用connectionTestQuery。允许HikariCP遵循其使用Connection.isValid()方法的默认行为。这需要JDBC4驱动程序。
connectionTestQuery
Connection.isValid()