天天看點

db2的jdbc驅動

依照 JDBC 規範,有四種類型的 JDBC 驅動程式體系結構:

Type 1:這類驅動程式将 JDBC API 作為到另一個資料通路 API 的映射來實作,如開放式資料庫連通性(Open Database Connectivity,ODBC)。這類驅動程式通常依賴本機庫,這限制了其可移植性。JDBC-ODBC 橋驅動程式就是 Type 1 驅動程式的最常見的例子。

Type 2:這類驅動程式部分用 JAVA 程式設計語言編寫,部分用本機代碼編寫。這些驅動程式使用特定于所連接配接資料源的本機用戶端庫。同樣,由于使用本機代碼,是以其可移植性受到限制。

Type 3:這類驅動程式使用純 JAVA 客戶機,并使用獨立于資料庫的協定與中間件伺服器通信,然後中間件伺服器将客戶機請求傳給資料源。

Type 4:這類驅動程式是純 JAVA,實作針對特定資料源的網絡協定。客戶機直接連接配接至資料源。

對于DB2 UDB V7.2來說,它不支援 Type 1 和 Type 4 的驅動程式,但是提供了分别支援 Type 2 和 Type 3 的驅動程式。

目前DB2安裝之後會自帶兩個驅動:

The IBM Data Server Driver for JDBC and SQLJ package includes two JDBC drivers:

  • db2jcc.jar - This driver is based on the JDBC 3 specification (Minimum required Java version 4)
  • db2jcc4.jar - This driver is based on the JDBC 4 or later specifications (Minimum required Java version 6)

如何檢視jdbc驅動的版本号:

The following command will retrieve the JCC driver version if executed from the command line:

java com.ibm.db2.jcc.DB2Jcc -version

如果沒有安裝驅動的的檢視jdbc驅動的版本指令:

Or for drivers that are not yet installed:

cd   <inst_path>/sqllib/java/

java -cp ./db2jcc.jar com.ibm.db2.jcc.DB2Jcc -version

java -cp ./db2jcc4.jar com.ibm.db2.jcc.DB2Jcc -version

db2jcc.jar和db2jcc4.jar的差別:

Answer

Both of them are DB2 JDBC driver jar files and are Type 4 drivers.

db2jcc.jar includes functions in the JDBC 3.0 and earlier specifications. If you plan to use those functions, include the db2jcc.jar in the application CLASSPATH.

db2jcc4.jar includes functions in JDBC 4.0 and later, as well as JDBC 3.0 and earlier specifications. If you plan to use those functions, include the db2jcc4.jar in the application CLASSPATH.

db2jcc.jar目前已經被棄用(deprecated, 但是仍然保留), 從DB2 11.1開始(jdbc3.72)開始将不再更新db2jcc.jar的新功能(仍存在),從DB211.5開始僅支援db2jcc4.jar,不再提供db2jcc.jar。

總之,db2jcc4.jar比db2jcc.jar更新更全面,安全性更好,且db2jcc4.jar包含db2jcc.jar的功能。是以建議使用db2jcc4.jar。

不同的db2版本對應相應的jdbc版本請參考:  https://www.ibm.com/support/pages/node/382667

參考文檔:

https://blog.csdn.net/davidmeng10/article/details/49800765

https://blog.csdn.net/travisli4891/article/details/4526044?ops_request_misc=&request_id=&biz_id=102&utm_term=db2jcc%E5%92%8Cdb2jcc4%E6%9C%89%E4%BB%80%E4%B9%88%E5%8C%BA%E5%88%AB&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-4526044

https://www.ibm.com/support/pages/difference-between-ibm-db2-jdbc-driver-files-db2jccjar-and-db2jcc4jar