Cannot initialise HikariCP pooled connection, Failure in loading native library db2jcct2

Multi tool use
Cannot initialise HikariCP pooled connection, Failure in loading native library db2jcct2
I'm trying to use HikariCP together with DB2 but get the following error:
Failure in loading native library db2jcct2,
java.lang.UnsatisfiedLinkError: db2jcct2
I have db2jcc4.jar file at my class path and only it.
And the following hikari properties file:
dataSourceClassName=com.ibm.db2.jcc.DB2SimpleDataSource
dataSource.user=username
dataSource.password=password
dataSource.databaseName=database
dataSource.serverName=server:50000
From what I understand Hikari tries to use type 2 driver and therefor it requires native library db2jcct2 is it right? And if yes, how can I say it implicitly to look for type 4 driver?
Update:
Proposed answer doesn't solve my issue. It can give direction but I could't get the correct answer only by reading that answer. At the same time you can find the answer in the comments to this question.
DB2SimpleDataSource
@MarkRotteveel, is it possible to change this by properties file?
– Anatoly
Jun 10 '15 at 14:47
This seems related: stackoverflow.com/questions/8325248/… So adding
dataSource.driverType=4
to your properties will probably fix it.– Mark Rotteveel
Jun 10 '15 at 14:55
dataSource.driverType=4
Note: I just fixed my previous comment as it had an incorrect
set
prefix.– Mark Rotteveel
Jun 10 '15 at 14:59
set
If you know how the javabeans conventions work, then the answer I linked answers your question directly (or at least, it gives you a hint to try). Another reason I initially posted a comment and not an answer was that I was not entirely sure if hikari directly accessed the properties of the specified datasource class (my proposed solution was a guess from knowledge). I have now posted an answer that explains this in more detail, although I still think it is a dupplicate.
– Mark Rotteveel
Jun 11 '15 at 12:50
2 Answers
2
This question is equivalent to Why is DB2 Type 4 JDBC Driver looking for native library db2jcct2?
If you were configuring the DataSource
in code you would need to do this:
DataSource
// Assuming dataSource is a com.ibm.db2.jcc.DB2SimpleDataSource
dataSource.setDriverType(4);
DataSources are javabeans. The convention of javabeans is that a pair of setXxxx
/getXxx
represents the property xxxx
. So a setter setDriverType
is equivalent to the property driverType
.
setXxxx
getXxx
xxxx
setDriverType
driverType
The hikari properties configure a datasource by defining the properties (which are then set through reflection). To do the equivalent of setDriverType(4)
, you need to use property driverType=4
. Given the convention used in that properties file that leads to:
setDriverType(4)
driverType=4
datasource.driverType=4
Thank you, I didn't know that DataSources are javabeans, now it's much more clear.
– Anatoly
Jun 11 '15 at 12:52
@Barring Although the javabeans specification brings a lot more than getters/setters, in a lot of ways any Java class with getters and setters can be considered a java bean (or at least, the conventions dictated by the javabeans specification can be applied). That said, the JDBC specification explicitly considers datasources to be java beans (see JDBC 4.2, section 9.6.1: DataSource properties follow the convention specified for properties of JavaBeans TM components in the JavaBeans 1.01 Specification.)
– Mark Rotteveel
Jun 11 '15 at 12:58
For DB2 type 4 driver, please try the following configuration.
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="springHikariCP" />
<property name="dataSourceClassName" value="com.ibm.db2.jcc.DB2SimpleDataSource"/>
<property name="maximumPoolSize" value="${db.maxTotal}" />
<property name="dataSourceProperties">
<props>
<prop key="driverType">4</prop>
<prop key="serverName">192.168.xxx.xxx</prop>
<prop key="databaseName">dbname</prop>
<prop key="portNumber">50000</prop>
<prop key="user">db2inst1</prop>
<prop key="password">password</prop>
</props>
</property>
<property name="jdbcUrl" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig" />
</bean>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
It is not Hikari that does this, it is the
DB2SimpleDataSource
that loads the type 2 driver.– Mark Rotteveel
Jun 10 '15 at 14:33