If you are using type 2 connectivity in your JDBC application,
and you are making a connection using the DriverManager interface,
you need to specify a URL in the DriverManager.getConnection call
that indicates type 2 connectivity.
IBM Data Server Driver for JDBC and SQLJ type 2 connectivity URL
syntax
>>---+-+-jdbc--:--db2--:--database----------+--+---------------------------+-+---><
| +-jdbc--:--db2os390--:--database-----+ '-:--| connection-options |-' |
| +-jdbc--:--db2os390sqlj--:--database-+ |
| '-jdbc--:--default--:--connection----' |
'-+-jdbc--:--db2os390--:-----+--+------------------------+--------------'
'-jdbc--:--db2os390sqlj--:-' '-| connection-options |-'
connection-options
.---------------------.
(1) V |
|----------+-----------------+-+--+-----------------------+--+----------------------+--+------------------------+--|
'-property=value;-' '-| special-registers |-' '-| global-variables |-' '-| query-acceleration |-'
special-registers
|--+--------------------------------------------------------------------------+--|
| .-,--------------------------------------------. |
| V | |
'-specialRegisters--=----special-register-name=special-register-value-+--;-'
global-variables
|--+------------------------------------------------------------------------------+--|
| .-,------------------------------------------. |
| V | |
'-globalSessionVariables--=----global-variable-name=global-variable-value-+--;-'
query-acceleration
|--+---------------------------------------------------+--------|
'-queryAcceleration--=--+-NONE-----------------+--;-'
+-ENABLE---------------+
+-ENABLE WITH FAILBACK-+
+-ELIGIBLE-------------+
'-ALL------------------'
Notes:
- property=value pairs,
the special-registers string, and the global-variables string can
be specified in any order.
IBM Data Server Driver for JDBC and SQLJ type 2 connectivity URL
options descriptions
The parts of the URL have the following
meanings:
- jdbc:db2: or jdbc:db2os390: or jdbc:db2os390sqlj: or jdbc:default:connection
- The meanings of the initial portion of the URL are:
- jdbc:db2: or jdbc:db2os390: or jdbc:db2os390sqlj:
- Indicates that the connection is to a DB2® for z/OS® or DB2 for Linux, UNIX, and Windows server.
jdbc:db2os390: and jdbc:db2os390sqlj: are for compatibility of programs
that were written for older drivers, and apply to IBM® Data Server Driver for JDBC and SQLJ type 2 connectivity to DB2 for z/OS only.
- jdbc:default:connection
- Indicates that the URL is for a connection to the local subsystem
through a DB2 thread that is
controlled by CICS®, IMS™, or the Java™ stored procedure environment.
- database
- A name for the database server.
- database is the database name that is defined
during installation, if the value of the serverName connection property
is null. If the value of serverName property is not null, database is
a database alias.
- 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.
Some
properties with an int data type have predefined constant field values.
You must resolve constant field values to their integer values before
you can use those values in the
url parameter.
For example, you cannot use com.ibm.db2.jcc.DB2BaseDataSource.TRACE_ALL
in a
url parameter. However, you can build a URL
string that includes com.ibm.db2.jcc.DB2BaseDataSource.TRACE_ALL,
and assign the URL string to a String variable. Then you can use the
String variable in the
url parameter:
String url =
"jdbc:db2:STLEC1" +
":user=dbadm;password=dbadm;" +
"traceLevel=" +
(com.ibm.db2.jcc.DB2BaseDataSource.TRACE_ALL) + ";";
Connection con =
java.sql.DriverManager.getConnection(url);
- specialRegisters=special-register-name=special-register-value,…special-register-name=special-register-value
- A list of special register settings for the JDBC connection. You
can specify one or more special register name and value pairs. Special
register name and value pairs must be delimited by commas (,). The
last pair must end with a semicolon (;). For example:
String url =
"jdbc:db2:STLEC1" +
":user=dbadm;password=dbadm;" +
"specialRegisters=CURRENT_PATH=SYSIBM,CURRENT CLIENT_USERID=test" + ";";
Connection con =
java.sql.DriverManager.getConnection(url);
For special registers that can be set through IBM Data Server Driver for JDBC and SQLJ Connection properties,
if you set a special register value in a URL string using specialRegisters,
and you also set that value in a java.util.Properties object
using the following form of getConnection, the
special register is set to the value from the URL string.
getConnection(String url, java.util.Properties info);
If
you specify a special register that is supported on the data server,
but you specify a value that is not supported on the data server,
the IBM Data Server Driver for JDBC and SQLJ returns
an error. If you specify a special register that is not supported
on the data server, the driver returns a warning.
You can specify
only one value for each special register using the specialRegisters
parameter. For special registers that take multiple values, such as
CURRENT PATH, CURRENT PACKAGE PATH, CURRENT PACKAGESET, you can specify
multiple values for a special register by using the DataSource interface
and the DB2DataSource.setSpecialRegisters method.
- globalSessionVariables=global-variable-name=global-variable-value,…global-variable-name=global-variable-value
- A list of global variable settings for the JDBC connection. You
can specify one or more global variable name and value pairs.
global
variable settings apply only to DB2 for z/OS Version
11 or later data servers.
global variable name and value pairs
must be delimited by commas (,). The last pair must end with a semicolon
(;). For example:
String url =
"jdbc:db2:STLEC1" +
":user=dbadm;password=dbadm;" +
"globalSessionVariables=SESSION.TEST=FAILED,SYSIBMADM.GET_ARCHIVE=Y" + ";";
Connection con =
java.sql.DriverManager.getConnection(url);
- queryAcceleration=value;
- Changes the value of the CURRENT QUERY ACCELERATION special register.
Possible
values are:
- NONE
- Specifies that no query acceleration is done.
- ENABLE
- Specifies that queries are accelerated only if DB2 determines that it is advantageous to do
so. If there is an accelerator failure while a query is running, or
the accelerator returns an error, DB2 returns
a negative SQLCODE to the application.
- ENABLE WITH FAILBACK
- Specifies that queries are accelerated only if DB2 determines that it is advantageous to do
so. If the accelerator returns an error during the PREPARE or first
OPEN for the query, DB2 executes
the query without the accelerator. If the accelerator returns an error
during a FETCH or a subsequent OPEN, DB2 returns
the error to the user, and does not execute the query.
- ELIGIBLE
- Specifies that queries are accelerated if they are eligible for
acceleration. DB2 does not use
cost information to determine whether to accelerate the queries. Queries
that are not eligible for acceleration are executed by DB2. If there is an accelerator failure while
a query is running, or the accelerator returns an error, DB2 returns a negative SQLCODE to the application.
- ALL
- Specifies that queries are accelerated if they are eligible for
acceleration. DB2 does not use
cost information to determine whether to accelerate the queries. Queries
that are not eligible for acceleration are not executed by DB2, and an SQL error is returned.
If there is an accelerator failure while a query is running, or the
accelerator returns an error, DB2 returns
a negative SQLCODE to the application.