7

I thought the Type 4 JDBC driver was pure Java and wouldn't require native libraries.

When I put db2jcc4.jar in the WEB-INF/lib directory of my Tomcat app packaged as a .war file, I get the following error when attempting to use the app: Got SQLException: com.ibm.db2.jcc.am.SqlException: [jcc][10389][12245][4.12.55] Failure in loading native library db2jcct2, java.lang.UnsatisfiedLinkError

The relevant application code is as follows and the exception is thrown due to the last line in the listing:

        import com.ibm.db2.jcc.DB2SimpleDataSource;

        // ...

        DB2SimpleDataSource main_db2_data_source = new DB2SimpleDataSource();
        main_db2_data_source.setUser(main_database_user);
        main_db2_data_source.setPassword(main_database_password);
        main_db2_data_source.setServerName(main_database_host);
        try {
          Integer main_database_port_integer = Integer.parseInt(main_database_port);
          main_db2_data_source.setPortNumber(main_database_port_integer);
        } catch (NumberFormatException exception) {
          throw new WebException("...");
        }
        Connection main_connection = null;
        try {
          main_connection = main_db2_data_source.getConnection();
necromancer
  • 23,916
  • 22
  • 68
  • 115

4 Answers4

19

I suspect the problem is that you haven't told it to use the type 4 driver - the same jar file contains both type 4 and type 2 drivers, I believe.

Try:

main_db2_data_source.setDriverType(4);
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
2

The db2 driver needs another jar that includes the license.

This license controls the connection type. If you are going to use "db2 connect" to connect to a mainframe as an i series you should use the corresponding license. If you are going to connect to a Linux UNIX or Windows server, the license is included when you get the "Data server client for JDBC"

AngocA
  • 7,655
  • 6
  • 39
  • 55
  • thanks, this wasn't the issue since i was not connecting to a mainframe, but at some point of time in the future i will need to connect and your advice will come in useful then. – necromancer Dec 05 '11 at 04:19
1

Also try this:

Goto Configure Build Path --> Libraries 
                             --> JRE System Libraries 
                                --> Native Library Location : Set this to %DB2HOME%/BIN 
                             (which is where db2jcct2.dll is saved)
JavaGeek
  • 475
  • 5
  • 14
0

Recently i have faced this issue, when i was connecting to DB2 from Glassfish server. for this i have followed below steps and resolved this issue. Please check it the below steps

step1) i have checked DB2 details in Domain.xml file.there i have seen only username,pwd,databaseName,serverName ,portnumber, But i havent see DriverType. Means Type of driver is 2 or 4.

2)for adding Type of driver i have logged into the Glassfish server admin console

Resources-->JDBC-->Connection pool -->our poolname --.add extra property

here i haved added as drivertype is 4.

Hence my problem has been solved

Thanks, Ramaiah Pillala.