Connecting To A Data Source Using Sqlj - IBM DB2 Manual

Table of Contents

Advertisement

Notes to Figure 27 on page 101:
Note
1
2
3a, 3b, 3c,
and 3d
4a , 4b, 4c,
and 4d
5
6
7

Connecting to a data source using SQLJ

In an SQLJ application, as in any other DB2 application, you must be connected to
a data source before you can execute SQL statements.
You can use one of six techniques to connect to a data source in an SQLJ program.
Two use the JDBC DriverManager interface, two use the JDBC DataSource interface,
one uses a previously created connection context, and one uses the default
connection.
Description
These statements import the java.sql package, which contains the JDBC core
API, and the sqlj.runtime package, which contains the SQLJ API. For
information on other packages or classes that you might need to access, see
"Java packages for SQLJ support".
String variables hvmgr and hvdeptno are host identifiers, which are equivalent
to DB2 host variables. See "Variables in SQLJ applications" for more
information.
These statements demonstrate how to connect to a data source using one of the
three available techniques. See "Connecting to a data source using SQLJ" for
more details.
Step 3b (loading the JDBC driver) is not necessary if you use JDBC 4.0.
These statements demonstrate how to execute SQL statements in SQLJ.
Statement 4a demonstrates the SQLJ equivalent of declaring an SQL cursor.
Statements 4b and 4c show one way of doing the SQLJ equivalent of executing
SQL FETCHes. Statement 4d shows how to do the SQLJ equivalent of
performing an SQL UPDATE. For more information, see "SQL statements in an
SQLJ application".
This try/catch block demonstrates the use of the SQLException class for SQL
error handling. For more information on handling SQL errors, see "Handling
SQL errors in an SQLJ application". For more information on handling SQL
warnings, see "Handling SQL warnings in an SQLJ application".
This is an example of a comment. For rules on including comments in SQLJ
programs, see "Comments in an SQLJ application".
This statement closes the connection to the data source. See "Closing the
connection to the data source in an SQLJ application".
Related concepts
"Java packages for SQLJ support" on page 110
"Variables in SQLJ applications" on page 110
"SQL statement execution in SQLJ applications" on page 112
"Comments in an SQLJ application" on page 112
Related tasks
"Connecting to a data source using SQLJ"
"Handling SQL errors in an SQLJ application" on page 154
"Handling SQL warnings in an SQLJ application" on page 155
"Closing the connection to a data source in an SQLJ application" on page 156
Related concepts
"How JDBC applications connect to a data source" on page 9
"Example of a simple SQLJ application" on page 101
"SQLJ and JDBC in the same application" on page 139
Chapter 4. SQLJ application programming
103

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents