Related concepts
“SQL statement execution in SQLJ applications” on page 112
Related tasks
“Connecting to a data source using SQLJ” on page 103
Related reference
“SQLJ with-clause” on page 283
“SQLJ assignment-clause” on page 291
“sqlj.runtime.ConnectionContext interface” on page 293
″DESCRIBE FOR STATIC″ (DB2 Installation Guide)
Controlling the execution of SQL statements in SQLJ
You can use selected methods of the SQLJ ExecutionContext class to control or
monitor the execution of SQL statements.
To use ExecutionContext methods, follow these steps:
1. Acquire the default execution context from the connection context.
There are two ways to acquire an execution context:
v Acquire the default execution context from the connection context. For
example:
ExecutionContext execCtx = connCtx.getExecutionContext();
v Create a new execution context by invoking the constructor for
ExecutionContext. For example:
ExecutionContext execCtx=new ExecutionContext();
2. 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.
3. 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.
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
Related concepts
“SQL statement execution in SQLJ applications” on page 112
Related tasks
“Making batch updates in SQLJ applications” on page 119
“Handling SQL warnings in an SQLJ application” on page 155
Related reference
“SQLJ context-clause” on page 288
“sqlj.runtime.ExecutionContext class” on page 307
142 Application Programming Guide and Reference for Java
™