SQL/MX Programming Manual for Java

SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java523726-003
3-8
Connection Contexts
Connection Contexts
A connection context associates the execution of each embedded SQL statement with
a particular JDBC connection to the database. Each SQL statement in an SQLJ
executable clause is implicitly or explicitly associated with a connection context. For a
particular SQLJ program, all SQL statements that are associated with the same
connection context class, including an implicit connection context, are included in the
same profile. See Profile on page 1-12.
Currently, an SQLJ program written for SQL/MX can connect only to an SQL/MX or
SQL/MP database while running on a NonStop server. You cannot establish
connections to heterogeneous database servers while running a customized SQLJ
program on a NonStop server. However, you can establish multiple connections to a
NonStop database by using explicit connection contexts. Explicit connection contexts
have these advantages:
Portability of applications. See Implicit Connection Contexts on page 3-8.
Flexibility in processing sets of database objects because separate profiles exist
for each connection context class. See Generating a Profile for Each Connection
Context Class on page 3-17.
Synchronized threads in a multithreaded application. See Multithreading on
page 3-23.
Implicit Connection Contexts
If you do not specify an explicit connection context in an SQLJ program, the SQLJ
translator generates code for a default, or implicit, connection context. For SQL/MX,
the name of the default connection context is:
sqlj.runtime.ref.DefaultContext
Although SQL/MX allows implicit connection contexts for SQLJ applications, such
applications might not be portable because some SQLJ run-time environments do not
provide a default connection context. Therefore, consider using explicit connection
contexts for SQLJ applications. See Explicit Connection Contexts on page 3-8.
Explicit Connection Contexts
This subsection explains how to code an explicit connection context according to these
steps:
Declaring a Connection Context Class on page 3-9
Declaring, Initializing, and Instantiating a Connection Context Object on page 3-9
Associating an SQLJ Executable Clause with a Connection Context on page 3-15
It also explains how to create separate profiles and modules for specific sets of
database objects. See Generating a Profile for Each Connection Context Class on
page 3-17.