0

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.

Community
  • 1
  • 1
Anatoly
  • 5,056
  • 9
  • 62
  • 136
  • 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
  • @MarkRotteveel, is it possible to change this by properties file? – Anatoly Jun 10 '15 at 14:47
  • 3
    This seems related: http://stackoverflow.com/questions/8325248/why-is-db2-type-4-jdbc-driver-looking-for-native-library-db2jcct2 So adding `dataSource.driverType=4` to your properties will probably fix it. – Mark Rotteveel Jun 10 '15 at 14:55
  • Note: I just fixed my previous comment as it had an incorrect `set` prefix. – Mark Rotteveel Jun 10 '15 at 14:59
  • @MarkRotteveel, `dataSource.driverType=4` solved my issue thank you. Nevertheless I couldn't agree that proposed answer solves my problem. I can't figure out how should I edit `hikari.properties` files and this isn't covered in proposed answer. You should have had to write your comment as answer. – Anatoly Jun 11 '15 at 10:38
  • 1
    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 Answers2

1

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
Community
  • 1
  • 1
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 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
0

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>
stanicmail
  • 743
  • 7
  • 19