SQL/MX Programming Manual for Java

SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java523726-003
3-13
Explicit Connection Contexts
Set the default connection context to the connection supplied for ctx by passing the
connection context ctx to the setDefaultContext() method:
SQLMXCtx.setDefaultContext(ctx);
Intantiate another connection context ctx1 to use the nondefault connection by
invoking the getDefaultContext() method:
SQLMXCtx ctx1 = SQLMXCtx.getDefaultContext();
Both connection contexts ctx and ctx1 share the same JDBC connection and
underlying database session. Because the connection context objects were
instantiated from the same connection context class, SQLMXCtx, the SQL statements
associated with those connection contexts are stored in the same profile.
For other types of connection context constructors and methods that you can use to
instantiate a connection context object, see Connection Context Constructors and
Methods on page 3-10.
Using an Existing Connection Context Object
Use the CtxClassName(ConnectionContext other) constructor to instantiate a
new connection context object based on an existing connection context object.
For example, the connection context object ctx2 is instantiated based on the existing
connection context object ctx:
ctx = SQLMXCtx.getDefaultContext();
...
ctx2 = new SQLMXCtx(ctx);
In the previous example, the new connection context object ctx2 and the preexisting
connection context object ctx share the same JDBC connection and underlying
database session. Because the connection context objects were instantiated from the
same connection context class, SQLMXCtx, the SQL statements associated with those
connection contexts are stored in the same profile.
In the next example, the new connection context object ctx and the preexisting
connection context object other share the same JDBC connection:
OtherCtx other = OtherCtx.getDefaultContext();
...
ctx = new SQLMXCtx(other);
However, because the connection context objects were instantiated from different
connection context classes, OtherCtx and SQLMXCtx, the SQL statements
associated with those connection contexts are stored in separate profiles.
For other types of connection context constructors and methods that you can use to
instantiate a connection context object, see Connection Context Constructors and
Methods on page 3-10.