You can use selected methods of the SQLJ ExecutionContext class
to control or monitor the execution of SQL statements.
Procedure
To use ExecutionContext methods, follow
these steps:
- Acquire the default execution context from the connection
context.
There are two ways to acquire an execution
context:
- Associate the execution context with an SQL statement.
To do that, specify an execution context after the connection
context in the execution clause that contains the SQL statement.
- Invoke ExecutionContext methods.
Some ExecutionContext methods are applicable before the associated
SQL statement is executed, and some are applicable only after their
associated SQL statement is executed.
For example, you can use
method getUpdateCount to count the number of rows
that are deleted by a DELETE statement after you execute the DELETE
statement.
Example
The following code demonstrates how to acquire an execution
context, and then use the getUpdateCount method
on that execution context to determine the number of rows that were
deleted by a DELETE statement. The numbers to the right of selected
statements correspond to the previously-described steps.ExecutionContext execCtx=new ExecutionContext(); 1
#sql [connCtx, execCtx] {DELETE FROM EMPLOYEE WHERE SALARY > 10000}; 2
System.out.println("Deleted " + execCtx.getUpdateCount() + " rows"); 3