SQL/MX Programming Manual for Java

SQLJ Programming
HP NonStop SQL/MX Programming Manual for Java523726-003
3-21
Explicit Execution Contexts
Associating an SQLJ Executable Clause with an Execution
Context
To associate an embedded SQL statement with an explicit execution context, place the
name of the execution context object inside square brackets [] (also known as a
context clause) within the SQLJ executable clause, after #sql and before the SQL
statement clause. For the syntax of the SQLJ executable clause, see Executable
Clause on page A-4.
The highlighted code sets the execution context for the DELETE statement to
execCtx:
import java.sql.*;
import sqlj.runtime.*;
#sql context SQLMXCtx;
public class MyProg
{
private SQLMXCtx ctx = null;
public MyProg()
{
try
{
ctx = SQLMXCtx.getDefaultContext();
ExecutionContext execCtx = new ExecutionContext();
#sql [ctx, execCtx] {DELETE FROM samdbcat.invent.partsupp
WHERE partnum = :partNum};
int rowCount = execCtx.getUpdateCount();
ctx.close();
}
catch(Exception e)
{
System.err.println("Exception: " + e);
}
}
}
If you specify the connection context object and execution context object together in an
SQLJ executable clause, you must list them in order, with the connection context listed
first and with the execution context listed second.