SQL/MX Programming Manual for Java
SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java—523726-003
3-9
Explicit Connection Contexts
Declaring a Connection Context Class
Declare the connection context class by specifying a connection declaration clause.
For the syntax, see the Connection Declaration Clause on page A-1.
Place the connection declaration clause where an SQLJ declaration clause is allowed
in an SQLJ program. The connection declaration clauses usually appear at the
beginning (or the top-level scope) of an SQLJ source file. The placement of the
connection declaration clause affects the visibility of the connection context class for
other classes. For more information, see Placement of Declaration Clauses on
page 3-2.
In this example, one connection declaration clause names a connection context class
SQLMXCtx, and another connection declaration clause names a connection context
class OtherCtx:
#sql context SQLMXCtx; /* Connection declaration clause */
#sql context OtherCtx; /* Connection declaration clause */
...
The SQLJ translator replaces each connection declaration clause with a Java definition
of the connection context class in the Java source (.java) file. CtxClassName is the
name of the connection context class you specified in the connection declaration
clause:
The connection context class implements the SQLJ ConnectionContext interface
and inherits its method signatures. The previous example shows the implementation of
part of the ConnectionContext interface and one of its constructors in the Java
source file.
Declaring, Initializing, and Instantiating a Connection
Context Object
After coding the connection declaration clause, declare and initialize a connection
context by using the connection context class definition. Place this declaration among
other Java variable declarations within the class of the SQLJ source file. For example,
declare the connection context ctx by using the SQLMXCtx class definition:
private SQLMXCtx ctx = null;
...
class CtxClassName
extends sqlj.runtime.ref.ConnectionContextImpl
//ConnectionContext interface
implements sqlj.runtime.ConnectionContext
{
public CtxClassName(java.sql.Connection conn)
throws java.sql.SQLException /* One of the constructors */
{
super(profiles, conn);
}
...