0

I have a Spring java web application. I am trying to use Hikaricp 2.2.5 for connection pooling with the following configuration.

Maven:

<dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP-java6</artifactId>
    <version>2.2.5</version>
    <scope>compile</scope>
</dependency>

XML:

<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
     <property name="minimumIdle" value="5"/>
     <property name="maximumPoolSize" value="200"/>
     <property name="dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"/>
     <property name="username" value="root"/>
     <property name="password" value="root"/>
     <property name="connectionTestQuery" value="SELECT 1"/>
     <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/app"/>
     <property name="autoCommit" value="true"/>
     <property name="connectionTimeout" value="30000"/>
     <property name="idleTimeout" value="600000"/>
     <property name="maxLifetime" value="1800000"/>
     <property name="poolName" value="LoginPool"/>
</bean>

I am getting the following error NoSuchMethodError.

Exception Stack Trace:

Caused by: java.lang.NoSuchMethodError: java.sql.Connection.getNetworkTimeout()I
    at com.zaxxer.hikari.util.PoolUtilities.isJdbc41Compliant(PoolUtilities.java:245)
    at com.zaxxer.hikari.pool.HikariPool.addConnection(HikariPool.java:412)
    at com.zaxxer.hikari.pool.HikariPool.fillPool(HikariPool.java:500)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:159)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:110)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:102)
    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2006)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1289)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1419)
    ... 109 more

How to resolve the issue?

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
phoenix
  • 985
  • 3
  • 17
  • 38
  • Judging from the stacktrace you aren't actually using 2.2.5 but 2.2.4. See [this issue](https://github.com/brettwooldridge/HikariCP/issues/188). – M. Deinum Nov 24 '14 at 12:56
  • @M.Deinum I have also seen the same issue. But, I think I have the mentioned maven configuration. I have HikariCP-java6-2.2.5 jar in my maven repo. – phoenix Nov 24 '14 at 13:17
  • Make sure that it is also used by your application that you don't have an old version somewhere in your classpath. Maybe try deleting the one from your repo and retrieve it again. – M. Deinum Nov 24 '14 at 13:21
  • I'm pretty sure that issue is fixed. As stated make sure you don't have other references or copies of old jars hanging around. Make sure you haven't put older versions some where in your server... – M. Deinum Nov 24 '14 at 13:27
  • @M.Deinum I checked thoroughly. Tomcat lib also does not have any. This is for the first time I got this jar. No local maven repo jars also. Only 2.2.5 is the jar. – phoenix Nov 24 '14 at 13:31
  • The `isJdbc41Compliant` method doesn't even exist in the 2.2.5 jar... Hence my suggestion there is something wrong in your environment. – M. Deinum Nov 24 '14 at 13:37
  • @M.Deinum Thank you. Intellij didn't build the new war. I resolved it. – phoenix Nov 24 '14 at 13:44
  • @M.Deinum How to provide the jdbcUrl value? Should it include database schema also? Like jdbc:mysql://localhost:3306/app? – phoenix Nov 24 '14 at 14:17
  • You shouldn't provide a `jdbcUrl` instead use `serverName` and `databaseName` properties. – M. Deinum Nov 24 '14 at 14:22
  • @M.Deinum Thanks a lot. How to have minimum number of connections? – phoenix Nov 24 '14 at 14:52

1 Answers1

2

Couple of things. The exception in your stacktrace:

at com.zaxxer.hikari.pool.HikariPool.addConnection(HikariPool.java:412)

does not line up with a call to isJdbc41Compliant() in the 2.2.5 branch. That code was removed in 2.2.5. Second, if you are using 2.2.5 and you are setting jdbcUrl you do not need dataSourceClassName, they are mutually exclusive. Try a clean build, and as a last resort go into your .m2/repositories directory and find and delete all HikariCP artifacts and let them re-download.

UPDATE: lastly, make sure you are using the latest MySQL driver if possible.

brettw
  • 10,664
  • 2
  • 42
  • 59