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
the logical name jdbc/defaultDataSource
v An explicitly created connection context that has been set as the default
connection context with the ConnectionContext.setDefaultContext method. This
method of creating a default connection context is not recommended.
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
WHERE EMPNO='000010'}; // Use default connection for
// executing an SQL statement
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
Contains the SQLJ run-time API.
java.sql
Contains the core JDBC API.
com.ibm.db2.jcc
Contains the driver-specific implementation of JDBC and SQLJ.
javax.naming
Contains methods for performing Java Naming and Directory Interface
(JNDI) lookup.
javax.sql
Contains methods for creating DataSource objects.
Related concepts
“Example of a simple SQLJ application” on page 101
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
™