Each executable SQLJ operation runs in an execution context. It is accessible through an execution context object, which is an instance of the sqlj.runtime.ExecutionContext class.
The execution context enables you to control the execution of the statement and to retrieve additional information on a statement execution.
The execution context of an executable SQL statement may be specified explicitly. If it is omitted, the default execution context of each connection context is used.
· Explicit execution context
To execute a statement on an explicit execution context, the execution context must be specified in the square brackets denoting the connection context.
import sqlj.runtime.ExecutionContext;
#sql context Ctx with (dataSource = "jdbc/Sys");
// ...
Ctx ctx = new Ctx(); ExecutionContext ec = new ExecutionContext();
#sql [ctx, ec] { DELETE FROM dbtab WHERE col = 'abc' };
int updateCount = ec.getUpdateCount(); |
Using an explicit execution context. A DELETE statement is executed using the explicit execution context ec. The execution context is used to retrieve the number of deleted rows.
· Implicit (default) execution context
Every connection context possesses a default execution context, which is used if no execution context is specified explicitly. The default execution context can be obtained from the getExecutionContext() method of the connection context.
#sql context Ctx with (dataSource = "jdbc/Sys"); #sql iterator StrIter (String, BigDecimal);
// ...
Ctx ctx = new Ctx(); StrIter strIter = null;
ctx.getExecutionContext().setMaxRows(10);
#sql [ctx] strIter = { SELECT name, salary FROM employees ORDER BY salary DESC };
ctx.getExecutionContext().setMaxRows(0); |
Using an implicit execution context. The getExecutionContext() method of a connection context is used to determine the default execution context of a statement. The setMaxRows() method is called on this execution context to limit the result set of the next query to 10 rows. After the execution of the query, this limit is reset.