Sqlj Connection Technique 1: Jdbc Drivermanager Interface - IBM DB2 Manual

Table of Contents

Advertisement

SQLJ connection technique 1: JDBC DriverManager interface

SQLJ connection technique 1 uses the JDBC DriverManager interface as the
underlying means for creating the connection.
To use SQLJ connection technique 1, follow these steps:
1. Execute an SQLJ connection declaration clause.
2. Load a JDBC driver by invoking the Class.forName method.
3. Invoke the constructor for the connection context class that you created in step
104
Application Programming Guide and Reference for Java
Related tasks
"Connecting to a data source using the DataSource interface" on page 15
"Performing positioned UPDATE and DELETE operations in an SQLJ
application" on page 114
"Making batch updates in SQLJ applications" on page 119
"Committing or rolling back SQLJ transactions" on page 153
"Closing the connection to a data source in an SQLJ application" on page 156
Related reference
"SQLJ with-clause" on page 283
"SQLJ connection-declaration-clause" on page 285
"SQLJ context-clause" on page 288
Doing this generates a connection context class. The simplest form of the
connection declaration clause is:
#sql context context-class-name;
The name of the generated connection context class is context-class-name.
v Invoke Class.forName this way:
Class.forName("com.ibm.db2.jcc.DB2Driver");
This step is unnecessary if you use the JDBC 4.0 driver.
1.
Doing this creates a connection context object that you specify in each SQL
statement that you execute at the associated data source. The constructor
invocation statement needs to be in one of the following forms:
connection-context-class connection-context-object=
new connection-context-class(String url, boolean autocommit);
connection-context-class connection-context-object=
new connection-context-class(String url, String user,
String password, boolean autocommit);
connection-context-class connection-context-object=
new connection-context-class(String url, Properties info,
boolean autocommit);
The meanings of the parameters are:
url A string that specifies the location name that is associated with the data
source. That argument has one of the forms that are specified in "Connect
to a data source using the DriverManager interface with the IBM Data
Server Driver for JDBC and SQLJ". The form depends on which JDBC
driver you are using.
user and password
Specify a user ID and password for connection to the data source, if the
data source to which you are connecting requires them.

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents