Connecting To A Data Source Using The Datasource Interface - IBM DB2 Manual

Table of Contents

Advertisement

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

Connecting to a data source using the DataSource interface

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 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.
jdbc:db2j:net:
Indicates that the connection is to a remote IBM Cloudscape server.
database
A name for the database server.
v database is a location name that is defined in the SYSIBM.LOCATIONS
catalog table.
All characters in the DB2 location name must be uppercase characters.
However, when the connection is to a DB2 for z/OS server, the IBM Data
Server Driver for JDBC and SQLJ converts lowercase characters in the
database value to uppercase.
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 whitespace
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://sysmvs1.stl.ibm.com:5021" +
"user=dbadm;password=dbadm;" +
"traceLevel=" +
(com.ibm.db2.jcc.DB2BaseDataSource.TRACE_ALL) + ";";
Connection con =
java.sql.DriverManager.getConnection(url);
If your applications need to be portable among data sources, you should use the
DataSource interface.
Using DriverManager to connect to a data source reduces portability because the
application must identify a specific JDBC driver class name and driver URL. The
driver class name and driver URL are specific to a JDBC vendor, driver
implementation, and data source.
When you connect to a data source using the DataSource interface, you use a
DataSource object.
The simplest way to use a DataSource object is to create and use the object in the
same application, as you do with the DriverManager interface. However, this
method does not provide portability.
Chapter 3. JDBC application programming
15

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents