SQL/MX Programming Manual for Java
SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java—523726-003
3-20
Execution Contexts
Execution Contexts
An execution context allows you some control over the execution of an SQL statement 
and enables you to retrieve information about the execution upon completion. Each 
SQL statement in an SQLJ executable clause is implicitly or explicitly associated with 
an execution context. 
Implicit Execution Contexts
If you do not specify an explicit execution context in an SQLJ program, the SQLJ 
translator uses a default, or implicit, execution context. The implicit execution context is 
created when the connection context class is instantiated. To retrieve the implicit 
execution context, use the getExecutionContext() method for the connection 
context object. For details, see Connection Context Methods on page 3-16.
Explicit Execution Contexts
To code an explicit execution context, declare and instantiate an execution context 
object and then associate an SQLJ executable clause with the execution context 
object. 
Declaring and Instantiating an Execution Context Object
Declare an execution context, for example execCtx, by using the 
sqlj.runtime.ExecutionContext class. Instantiate an execution context object 
of the ExecutionContext class as highlighted in this example:
#sql context SQLMXCtx;
public class MyProg
{
private SQLMXCtx ctx = null;
public MyProg()
{
try
{
ctx = SQLMXCtx.getDefaultContext();
//Create an instance of an execution context object
sqlj.runtime.ExecutionContext execCtx = 
new sqlj.runtime.ExecutionContext();
...
The constructor for the ExecutionContext class is invoked when you instantiate the 
object. 
Caution. Execution contexts should not be shared among threads in a multithreaded 
application. For more information, see Multithreading on page 3-23.










