software:db2:db2_jdbc_drivers
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
software:db2:db2_jdbc_drivers [2013/04/01 08:35] – seela | software:db2:db2_jdbc_drivers [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== DB2 JDBC drivers ====== | ||
- | |||
- | There are 2 types of jdbc drivers supported | ||
- | |||
- | * The legacy based CLI driver(Type 2) | ||
- | * The new JDBC Universal driver(Type 4) | ||
- | |||
- | **History behind the jdbc drivers** | ||
- | |||
- | In order to understand how we came to the development of the DB2 Universal Driver, you need to understand how the JDBC specification defines the different types of drivers in the Java world. | ||
- | |||
- | **Type 1 driver** | ||
- | This type of driver code maps directly to a high level native API. JDBC and ODBC | ||
- | are similar APIs, so this type of driver is usually associated with the JDBC-ODBC | ||
- | | ||
- | This driver does not have too much context with respect to the DB2 UDB product. | ||
- | |||
- | **Type 2 driver** | ||
- | |||
- | A T2 driver has a native component that is part of the driver, but separate from | ||
- | the data access API. The native component and the Java component make up this driver. | ||
- | For DB2 UDB, the DB2 CLI libraries comprise the native component. | ||
- | |||
- | **Type 3 driver** | ||
- | |||
- | This is a Java client that communicates using a database independent protocol. | ||
- | Since the protocol is database independent, | ||
- | | ||
- | |||
- | **Type 4 driver** | ||
- | |||
- | This driver is pure Java and implements the network protocol for a specific data | ||
- | source. The client connects directly to the data source. | ||
- | |||
- | DB2 JDBC support is provided as part of the Java enablement option for DB2 UDB clients and servers. | ||
- | You just need to make sure that you have the appropriate Java developer kit downloaded | ||
- | |||
- | Here is a comparison table | ||
- | |||
- | ^CLI legacy driver | ||
- | |db2java.zip | ||
- | |IN Unix: Use Type2 by placing|java/ | ||
- | |java/ | ||
- | ^Connection comparison | ||
- | |DB2 uses CLI interface | ||
- | |CLI is the native component | ||
- | |that communicates with the | ||
- | |database server.This legacy based | This is a pure Java driver,run independently | | ||
- | |CLI driver requires common client |of what product is installed on the machine| | ||
- | |code|| | ||
- | ^Driver Initialization | ||
- | | 3 steps necessary to load this |Universal supports type 2 and Type4| | ||
- | |driver. 1. Import java.sql* core|from a single driver.h network communication| | ||
- | |2. Load the JDBC driver Class.forName|uses DRDA to communicate to server and| | ||
- | |(COM.ibm.db2.jdbc.app.DB2Driver).|and flow requests to the database server| | ||
- | |3.Specify the connection URL: |The following means that a Type 2 driver is | | ||
- | |DriverManager getConnection | ||
- | |jdbc: | ||
- | | |jdbc: | ||
- | |||
- | |||
- | ^Error Handling | ||
- | |The legacy driver gets its error|The universal driver does not attempt to | | ||
- | |messages from the DB2 product and|recreate pre-existing SQL error codes| | ||
- | |essentially spits out the entire |has its own defined error codes | | ||
- | |error message back to the application|in the range +/-4200 and +/-4299| | ||
- | |||
- | < | ||
- | |||
- | IBM Data Server Driver for JDBC and SQLJ (type 2 and type 4) | ||
- | |||
- | The IBM Data Server Driver for JDBC and SQLJ is a single driver that includes JDBC type 2 and JDBC type 4 behavior. When an application loads the IBM Data Server Driver for JDBC and SQLJ, a single driver instance is loaded for type 2 and type 4 implementations. The application can make type 2 and type 4 connections using this single driver instance. The type 2 and type 4 connections can be made concurrently. IBM Data Server Driver for JDBC and SQLJ type 2 driver behavior is referred to as IBM Data Server Driver for JDBC and SQLJ type 2 connectivity. IBM Data Server Driver for JDBC and SQLJ type 4 driver behavior is referred to as IBM Data Server Driver for JDBC and SQLJ type 4 connectivity. | ||
- | |||
- | Two versions of the IBM Data Server Driver for JDBC and SQLJ are available. IBM Data Server Driver for JDBC and SQLJ version 3.5x is JDBC 3.0-compliant. IBM Data Server Driver for JDBC and SQLJ version 4.x is compliant with JDBC 4.0 or later. | ||
- | The IBM Data Server Driver for JDBC and SQLJ is the default driver for Java routines. | ||
- | |||
- | The DB2 JDBC Type 2 Driver for Linux, UNIX and Windows will not be supported in future releases. You should therefore consider moving to the IBM Data Server Driver for JDBC and SQLJ. | ||
- | |||
- | Compatibility for IBM Data Server Driver for JDBC and SQLJ type 4 connectivity | ||
- | |||
- | The IBM Data Server Driver for JDBC and SQLJ is always downward compatible with DB2 | ||
- | databases at the previous release level. For example, IBM Data Server Driver for JDBC and SQLJ type 4 connectivity from the IBM Data Server Driver for JDBC and SQLJ version 3.61, which is shipped with DB2 Database for Linux, UNIX, and Windows Version 9.7 Fix Pack 3, to a DB2 Database for Linux, UNIX, and Windows Version 8 database is supported. | ||
- | |||
- | |||
- | Compatibility for IBM Data Server Driver for JDBC and SQLJ type 2 connectivity | ||
- | |||
- | In general, IBM Data Server Driver for JDBC and SQLJ type 2 connectivity is intended for connections to the local database system, using the driver version that is shipped with that database version. For example, version 3.6x of the IBM Data Server Driver for JDBC and SQLJ is shipped with DB2 Database for Linux, UNIX, and Windows Version 9.5 and Version 9.7, | ||
- | |||
- | However, for IBM Data Server Driver for JDBC and SQLJ type 2 connectivity to a local DB2 Database for Linux, UNIX, and Windows database, the database version can be one version earlier or one version later than the DB2 Database for Linux, UNIX, and Windows version with which the driver was shipped. For IBM Data Server Driver for JDBC and SQLJ type 2 connectivity to a local DB2 for z/OS subsystem, the subsystem version can be one version later than the DB2 for z/OS version with which the driver was shipped. | ||
- | |||
- | For our Community version: | ||
- | DB2 Version 10.1 Fix Pack 1 3.64.xx, 4.14.xx | ||
- | DB2 Version 10.1 3.63.xx, 4.13.xx | ||
- | |||
- | |||
- | How DB2 applications connect to a data source using the DriverManager interface with the DB2 JDBC Type 2 Driver | ||
- | |||
- | A JDBC application can establish a connection to a data source using the JDBC DriverManager interface, which is part of the java.sql package. | ||
- | JDBC Type 2 Driver for Linux | ||
- | you load the driver by invoking the Class.forName method with the following argument: | ||
- | |||
- | COM.ibm.db2.jdbc.app.DB2Driver | ||
- | |||
- | The following code demonstrates loading the DB2 JDBC Type 2 Driver: | ||
- | |||
- | try { | ||
- | // Load the DB2 JDBC Type 2 Driver with DriverManager | ||
- | Class.forName(" | ||
- | } catch (ClassNotFoundException e) { | ||
- | | ||
- | } | ||
- | |||
- | The catch block is used to print an error if the driver is not found. | ||
- | After you load the driver, you connect to the data source by invoking the DriverManager.getConnection method. You can use one of the following forms of getConnection: | ||
- | |||
- | getConnection(String url); | ||
- | getConnection(String url, user, password); | ||
- | getConnection(String url, java.util.Properties info); | ||
- | |||
- | The url argument represents a data source. | ||
- | |||
- | For the DB2 JDBC Type 2 Driver, specify a URL of the following form: | ||
- | |||
- | jdbc:db2: | ||
- | jdbc:db2: indicates that the connection is to a DB2 data source | ||
- | database | ||
- | A database alias. The alias refers to the DB2 database catalog entry on the DB2 client. | ||
- | The info argument is an object of type java.util.Properties that contains a set of driver properties for the connection. | ||
- | |||
- | |||
- | The info argument is an object of type java.util.Properties that contains a set of driver properties for the connection. | ||
- | |||
- | |||
- | eg: | ||
- | Example: Setting the user ID and password in user and password parameters: | ||
- | |||
- | String url = " | ||
- | // Set URL for data source | ||
- | String user = " | ||
- | String password = " | ||
- | Connection con = DriverManager.getConnection(url, | ||
- | // Create connection | ||
- | |||
- | Example: Setting the user ID and password in a java.util.Properties object: | ||
- | |||
- | Properties properties = new Properties(); | ||
- | properties.put(" | ||
- | properties.put(" | ||
- | String url = " | ||
- | // Set URL for data source | ||
- | Connection con = DriverManager.getConnection(url, | ||
- | // Create connection | ||
- | |||
- | |||
- | |||
- | |||
- | TYPE 4: | ||
- | Connecting to a data source using the DriverManager interface with the IBM Data Server Driver for JDBC and SQLJ | ||
- | |||
- | A JDBC application can establish a connection to a data source using the JDBC DriverManager interface, which is part of the java.sql package. | ||
- | |||
- | The steps for establishing a connection are: | ||
- | |||
- | Load the JDBC driver by invoking the Class.forName method. | ||
- | If you are using JDBC 4.0 or later, you do not need to explicitly load the JDBC driver. | ||
- | For IBM Data Server Driver for JDBC and SQLJ, you load the driver by invoking the Class.forName method with the following argument: | ||
- | |||
- | com.ibm.db2.jcc.DB2Driver | ||
- | |||
- | The following code demonstrates loading the IBM Data Server Driver for JDBC and SQLJ: | ||
- | |||
- | try { | ||
- | // Load the IBM Data Server Driver for JDBC and SQLJ with DriverManager | ||
- | Class.forName(" | ||
- | } catch (ClassNotFoundException e) { | ||
- | | ||
- | } | ||
- | |||
- | |||
- | |||
- | The catch block is used to print an error if the driver is not found. | ||
- | |||
- | 2. Connect to a data source by invoking the DriverManager.getConnection method. | ||
- | You can use one of the following forms of getConnection: | ||
- | |||
- | getConnection(String url); | ||
- | getConnection(String url, user, password); | ||
- | getConnection(String url, java.util.Properties info); | ||
- | |||
- | For IBM Data Server Driver for JDBC and SQLJ type 4 connectivity, | ||
- | |||
- | The url argument represents a data source, and indicates what type of JDBC connectivity you are using. | ||
- | The info argument is an object of type java.util.Properties that contains a set of driver properties for the connection. | ||
- | |||
- | THERE ARE SEVERAL WAYS TO SPECIFY A USERNAME/ | ||
- | |||
- | |||
- | Example: Establishing a connection and setting the user ID and password in a URL: | ||
- | |||
- | String url = " | ||
- | " | ||
- | |||
- | // Set URL for data source | ||
- | Connection con = DriverManager.getConnection(url); | ||
- | // Create connection | ||
- | |||
- | Example: Establishing a connection and setting the user ID and password in user and password parameters: | ||
- | |||
- | String url = " | ||
- | // Set URL for data source | ||
- | String user = " | ||
- | String password = " | ||
- | Connection con = DriverManager.getConnection(url, | ||
- | // Create connection | ||
- | |||
- | Example: Establishing a connection and setting the user ID and password in a java.util.Properties object: | ||
- | |||
- | Properties properties = new Properties(); | ||
- | properties.put(" | ||
- | properties.put(" | ||
- | String url = " | ||
- | // Set URL for data source | ||
- | Connection con = DriverManager.getConnection(url, | ||
- | // Create connection | ||
- | |||
- | |||
- | |||
- | IBM Data Server Driver for JDBC and SQLJ type 4 connectivity URL option descriptions | ||
- | |||
- | The parts of the URL have the following meanings: | ||
- | |||
- | jdbc:db2: or jdbc: | ||
- | The meanings of the initial portion of the URL are: | ||
- | |||
- | jdbc:db2: | ||
- | Indicates that the connection is to a DB2 Database for Linux, UNIX, and Windows. | ||
- | |||
- | jdbc: | ||
- | Indicates that the connection is to a remote IBM Cloudscape server. | ||
- | |||
- | server | ||
- | The domain name or IP address of the data source. | ||
- | port | ||
- | The TCP/IP server port number that is assigned to the data source. This is an integer between 0 and 65535. The default is 446. | ||
- | |||
- | property=value; | ||
- | A property and its value for the JDBC connection. You can specify one or more property and value pairs. Each property and value pair, including the last one, must end with a semicolon (;). Do not include spaces or other white space characters anywhere within the list of property and value strings | ||
- | |||
- | |||
- | |||
- | If the database version to which your applications are connecting is later than the database version with which the driver was shipped, the applications cannot use features of the later database version. | ||
- | |||
- | ====JCC driver Version==== | ||
- | \\ | ||
- | **How to find out the JCC driver version being used in your application** \\ | ||
- | \\ | ||
- | < | ||
- | % db2jcc -version | ||
- | red 278 % source ~db2leduc/ | ||
- | red 280 % db2jcc -version | ||
- | IBM DB2 JDBC Universal Driver Architecture 3.65.77 | ||
- | |||
- | Alternatively | ||
- | |||
- | red 281 % java com.ibm.db2.jcc.DB2Jcc -version | ||
- | IBM DB2 JDBC Universal Driver Architecture 3.65.77 | ||
- | |||
- | red 283 % / | ||
- | IBM DB2 JDBC Universal Driver Architecture 3.65.77 | ||
- | |||
- | |||
- | </ | ||
- | \\ | ||
- | |||
- | **How to display the version of the Universal Driver** \\ | ||
- | \\ | ||
- | < | ||
- | red 282 % / | ||
- | IBM Data Server Driver for JDBC and SQLJ 4.15.82 | ||
- | </ | ||
software/db2/db2_jdbc_drivers.1364819724.txt.gz · Last modified: by seela