Databases Reference
In-Depth Information
Example 5-28 shows how to create the ExecutionContext object and use its
method getUpdateCount to retrieve the number of rows deleted by the DELETE
statement.
Example 5-28 Creating ExecutionContext object
#sql context ctx; // this should be outside the class
String url = "jdbc:db2:sample";
Class.forName("com.ibm.db2.jcc.DB2Driver").newInstance();
Connection con=DriverManager.getConnection(url);
ctx ctx1=new ctx(con);
ExecutionContext exectx1=ctx1.getExecutionContext();
#sql[ctx1,exectx1] { DELETE FROM purchaseorder WHERE
status='UnShipped'}
int i=exectx1.getUpdateCount();
5.12.3 Iterators
SQLj defines iterators for selecting multiple rows using the SELECT statement.
Iterators are the SQLj equivalent of ResultSet in Java and cursors in other
programming languages.
To iterators, the application needs to create an iterator class by defining the
iterator and an object of that class. The result of the SELECT statement can be
assigned to this object.
SQLj provides two types of iterators:
Named iterators
Positioned iterators
Named iterators
Named iterators identify a row by the name of the column in the result set. So
while defining the named iterator, you need to specify the name of the columns
and their data types selected by the SELECT statement.
Example 5-29 shows how to use the named iterator in an SQLj program.
Example 5-29 Using named iterators
#sql iterator namediterator(int poid,String status)
namediterator iterator1;
#sql [ctx1] iterator1={ select poid,status from purchaseorder };
while(iterator1.next())
{
System.out.println("poid: " + iterator1.poid() + "Status: "+
Search WWH ::




Custom Search