Java Packages For Sqlj Support; Variables In Sqlj Applications - IBM DB2 Manual

Table of Contents

Advertisement

You use the default connection by specifying your SQL statements without a
connection context object. When you use this technique, you do not need to load a
JDBC driver unless you explicitly use JDBC interfaces in your program.
The default connection context can be:
v The connection context that is associated with the data source that is bound to
v An explicitly created connection context that has been set as the default
In a stored procedure that runs on DB2 for z/OS, or for a CICS or IMS application,
when you use the default connection, DB2 uses the implicit connection.
The following SQLJ execution clause does not have a connection context, so it uses
the default connection context.
#sql {SELECT LASTNAME INTO :empname FROM EMPLOYEE

Java packages for SQLJ support

Before you can execute SQLJ statements or invoke JDBC methods in your SQLJ
program, you need to be able to access all or parts of various Java packages that
contain support for those statements.
You can do that either by importing the packages or specific classes, or by using
fully-qualified class names. You might need the following packages or classes for
your SQLJ program:
sqlj.runtime
java.sql
com.ibm.db2.jcc
javax.naming
javax.sql

Variables in SQLJ applications

In DB2 programs in other languages, you use host variables to pass data between
the application program and DB2. In SQLJ programs, In SQLJ programs, you can
use host variables or host expressions.
A host expression begins with a colon (:). The colon is followed by an optional
parameter mode identifier (IN, OUT, or INOUT), which is followed by a
parenthesized expression clause.
110
Application Programming Guide and Reference for Java
the logical name jdbc/defaultDataSource
connection context with the ConnectionContext.setDefaultContext method. This
method of creating a default connection context is not recommended.
WHERE EMPNO='000010'}; // Use default connection for
Contains the SQLJ run-time API.
Contains the core JDBC API.
Contains the driver-specific implementation of JDBC and SQLJ.
Contains methods for performing Java Naming and Directory Interface
(JNDI) lookup.
Contains methods for creating DataSource objects.
Related concepts
"Example of a simple SQLJ application" on page 101
// executing an SQL statement

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents