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

1.7k views Asked by At

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.

2

There are 2 answers

2
Mark Rotteveel On BEST ANSWER

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:

// 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/getXxxrepresents the property xxxx. So a setter setDriverType is equivalent to the property 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:

datasource.driverType=4
0
stanicmail On

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>