EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #120 background imageLoading...
Page #120 background image
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
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.
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.
2. Load a JDBC driver by invoking the Class.forName method.
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.
3. Invoke the constructor for the connection context class that you created in step
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.
104 Application Programming Guide and Reference for Java

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability