How Jdbc Applications Connect To A Data Source; Sqlj - IBM DB2 Manual

Table of Contents

Advertisement

Notes to Figure 1 on page 7:
Note
1
2
3a and 3b
4a and 4b
5
6

How JDBC applications connect to a data source

Before you can execute SQL statements in any SQL program, you must be
connected to a data source.
The IBM Data Server Driver for JDBC and SQLJ supports type 2 and type 4
connectivity. Connections to DB2 databases can use type 2 or type 4 connectivity.
Connections to IBM Informix Dynamic Server (IDS) databases can use type 4
connectivity.
The following figure shows how a Java application connects to a data source using
IBM Data Server Driver for JDBC and SQLJ type 2 connectivity.
Description
This statement imports the java.sql package, which contains the JDBC core API.
For information on other Java packages that you might need to access, see "Java
packages for JDBC support".
String variable empNo performs the function of a host variable. That is, it is
used to hold data retrieved from an SQL query. See "Variables in JDBC
applications" for more information.
These two sets of statements demonstrate how to connect to a data source using
one of two available interfaces. See "How JDBC applications connect to a data
source" for more details.
Step 3a (loading the JDBC driver) is not necessary if you use JDBC 4.0.
These two sets of statements demonstrate how to perform a SELECT in JDBC.
For information on how to perform other SQL operations, see "JDBC interfaces
for executing SQL".
This try/catch block demonstrates the use of the SQLException class for SQL
error handling. For more information on handling SQL errors, see "Handling an
SQLException under the IBM Data Server Driver for JDBC and SQLJ". For
information on handling SQL warnings, see "Handling an SQLWarning under
the IBM Data Server Driver for JDBC and SQLJ".
This statement disconnects the application from the data source. See
"Disconnecting from data sources in JDBC applications".
Related concepts
"Example of a simple JDBC application" on page 7
"Java packages for JDBC support" on page 21
"How JDBC applications connect to a data source"
"Variables in JDBC applications" on page 23
"JDBC interfaces for executing SQL" on page 24
Related tasks
"Handling an SQLWarning under the IBM Data Server Driver for JDBC and
SQLJ" on page 81
"Disconnecting from data sources in JDBC applications" on page 99
Chapter 3. JDBC application programming
9

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents