問題描述
我認為 Type 4 JDBC 驅(qū)動程序是純 Java 并且不需要本地庫.
I thought the Type 4 JDBC driver was pure Java and wouldn't require native libraries.
當我將 db2jcc4.jar 放入打包為 .war 文件的 Tomcat 應用程序的 WEB-INF/lib 目錄中時,嘗試使用該應用程序時出現(xiàn)以下錯誤:Got SQLException: com.ibm.db2.jcc.am.SqlException: [jcc][10389][12245][4.12.55] 加載原生庫 db2jcct2 失敗,java.lang.UnsatisfiedLinkError
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
相關(guān)應用代碼如下,由于清單最后一行而拋出異常:
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();
推薦答案
我懷疑問題是你沒有告訴它使用類型 4 驅(qū)動程序 - 同一個 jar 文件包含類型 4 和類型 2 驅(qū)動程序,我相信.
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.
試試:
main_db2_data_source.setDriverType(4);
這篇關(guān)于為什么 DB2 Type 4 JDBC Driver 正在尋找本機庫 db2jcct2?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!