为什么DB2 Type 4 JDBC Driver寻找本地库db2jcct2? [英] Why is DB2 Type 4 JDBC Driver looking for native library db2jcct2?

查看:140
本文介绍了为什么DB2 Type 4 JDBC Driver寻找本地库db2jcct2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为Type 4 JDBC驱动是纯Java,不需要本地库。



当将db2jcc4.jar放在WEB-INF / lib目录中时我的Tomcat应用程序打包成.war文件,尝试使用该应用程序时收到以下错误: Got SQLException:com.ibm.db2.jcc.am.SqlException:[jcc] [10389] [12245] [4.12.55]加载本地库db2jcct2,java.lang.UnsatisfiedLinkError



相关应用程序代码如下,由于列表中的最后一行,抛出异常:

  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(...);
}
连接main_connection = null;
try {
main_connection = main_db2_data_source.getConnection();


解决方案

我怀疑问题是你没有告诉它使用类型4驱动程序 - 相同的jar文件包含类型4和类型2驱动程序,我相信。



尝试:

  main_db2_data_source.setDriverType(4); 


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();

解决方案

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);

这篇关于为什么DB2 Type 4 JDBC Driver寻找本地库db2jcct2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆