Java programs talk to DB2 for z/OS through the IBM Data Server Driver for JDBC and SQLJ. One driver JAR gives you both type 2 (same LPAR, native attachment) and type 4 (DRDA over TCP/IP to DDF). This page covers the driver, URLs, how you obtain a Connection, TLS properties, driver packages, and connection pooling.
Do not start new work on the old Universal Driver class names in COM.ibm.db2 or on db2jcc.jar (JDBC 3). Current support is:
You need a Java runtime IBM documents for that driver version (historically Java 5+; shops today run current IBM Semeru or Oracle JDK levels the driver lists). On a z/OS LPAR that has no Db2, the optional z/OS Application Connectivity to Db2 feature still provides type 4 to a remote data server.
XA / JTA distributed transactions are a type 4 feature against Db2 for z/OS Version 7 or later. Type 2 in CICS Liberty still goes through the CICS-Db2 attachment (EXEC SQL equivalent), which is a different performance and zIIP story.
A CICS Liberty benchmark Redpaper (REDP-5208) is the usual citation when architects argue type 2 versus type 4 on-platform: type 2 avoids DDF but pays native CPU; type 4 is more offloadable and matches distributed clients.
| URL | Kind | Notes |
|---|---|---|
| jdbc:db2://host:446/DB2A | Type 4 | TCP/IP to DDF; LOCATION uppercase |
| jdbc:db2://host:448/DB2A:sslConnection=true; | Type 4 TLS | SECPORT + AT-TLS |
| jdbc:db2:DB2A | Type 2 | Local subsystem / location on the same LPAR |
| jdbc:default:connection | Type 2 inherited | CICS, IMS, or Java stored procedure thread |
jdbc:db2://server:port/database:connection-options
Prefix jdbc:db2j:net: is Cloudscape; jdbc:ids: is Informix; jdbc:ibmdb: means any IBM data server the driver supports. For Db2 for z/OS, jdbc:db2: is the everyday prefix.
jdbc:db2:LOCATION or the compatibility forms jdbc:db2os390: and jdbc:db2os390sqlj:. jdbc:default:connection means “the thread I already have” in CICS, IMS, or a Java routine. You cannot pass a user ID and password on a CICS inherited connection.
123456String url = "jdbc:db2://db2a.example.com:448/DB2A" + ":user=APPUSER;password=secret;" + "sslConnection=true;" + "jdbcCollection=NULLID;"; Connection con = DriverManager.getConnection(url);
Two standard ways to get a java.sql.Connection:
Useful driver properties (also valid on the URL):
Always close Connection, Statement, and ResultSet (try-with-resources). A leaked connection is a leaked DBAT until idle timeout.
Type 4 SQL runs through packages bound by the DB2Binder utility (com.ibm.db2.jcc.DB2Binder) into a collection, usually NULLID. If jdbcCollection does not match, you see package-not-found SQLCODEs at connect or first SQL. SQLJ uses a different collection from db2sqljcustomize -collection; jdbcCollection does not redirect SQLJ.
A connection is not a cheap object: TCP, optional TLS handshake, RACF, DBAT allocation, special registers. Connection pooling keeps a set of authenticated connections ready.
Pool rules beginners break: calling Connection.close() on a pooled connection returns it to the pool (good) only if you obtained it from the DataSource; wrapping and closing the physical socket yourself defeats the pool. Do not change autocommit or isolation on a borrowed connection without resetting them. Never share one Connection across threads.
JDBC is a universal plug. The IBM driver is the adapter that fits Db2. Type 2 is shouting through the wall to Db2 in the same house (same LPAR). Type 4 is phoning Db2 on the DDF number (host, port, location name). The URL is the phone number. A DataSource is the office receptionist who keeps a few lines already dialed (the pool) so you do not wait for the ringtone every time you ask a question.
1. What is the supported JDBC driver for Db2 for z/OS?
2. Which URL is type 4 to location DB2A on port 448 with TLS?
3. When does IBM recommend type 2 connectivity?
4. Where do the JDBC driver packages live on the server?
5. Why pool connections to DDF?