EasyManuals Logo

IBM DB2 User Manual

IBM DB2
585 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #158 background imageLoading...
Page #158 background image
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

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the IBM DB2 and is the answer not in the manual?

IBM DB2 Specifications

General IconGeneral
DeveloperIBM
Initial Release1983
LicenseProprietary
Written inC, C++
CategoryDatabase Management System (RDBMS)
Operating SystemLinux, Windows
Programming LanguagesC, C++
Data ModelsRelational
EditionsCommunity, Standard, Advanced
Key Featureshigh availability, scalability