Acquiring a DriverManager connection to a database

Using the DriverManager class, the connection to the database is identified by a database Uniform Resource Locator (URL) that is provided to the JDBC driver.

About this task

A DriverManager connection is configured for an OSGi JVM server by specifying the Db2® JDBC jars and native DLLs in the JVM profile OSGI_BUNDLES and LIBPATH_SUFFIX JVM profile.

In a Liberty JVM server, the DriverManager configuration is provided by the CICS® JDBC Liberty feature.

The JDBC driver recognizes two types of URL:
Default URL
A default URL does not include the location name of a Db2 subsystem. A default URL for Db2 for z/OS® can be specified in one of two formats:

jdbc:db2os390sqlj:
or
jdbc:default:connection
When a default URL is specified, the application is given a connection to the local Db2 to which CICS is connected. If your installation uses Db2 data sharing, you can access all the data in your sysplex from the local Db2.
Explicit URL
An explicit URL includes the location name of a Db2 subsystem. The basic structure of an explicit URL for Db2 for z/OS is:

jdbc:db2os390:<location-name>
or
jdbc:db2os390sqlj:<location-name>
Typically, the location name is the name of the local Db2 to which CICS is connected. However, you can specify the name of a remote Db2 to access. In this case, CICS uses the local Db2 as a pass-through, and uses Db2 Distributed Data Facilities to access the remote Db2.

It is advisable to use a default URL when accessing Db2 with type 2 connectivity. The use of an explicit URL might cause specific actions when a connection closes that could be inconvenient when multiple programs are used in the same application suite. Also, when a default URL is used, the behavior of the connection is not affected by the JDBC driver version.

To acquire a connection, your Java™ application needs to invoke the getConnection() method with the URL. For example:
Connection connection =
DriverManager.getConnection("jdbc:default:connection");

When connecting an OSGi Java program to Db2, add com.ibm.db2.jcc;resolution:=optional to the Import-Package in your bundle manifest.