Databases Reference
In-Depth Information
iterator1.status());
}iterator1.close();
Positioned iterators
A positioned iterator identifies a row by its position in the result set. So while
defining the position iterator, you need to give only the data types of the columns.
Example 5-30 shows how to use the positioned iterator in SQLj.
Example 5-30 Using positioned iterators
#sql iterator positionedIterator(int, String);
String status=null;
int poid=0;
positionedIterator iterator1;
#sql [ctx1] iterator1={ select poid,status from purchaseorder };
#sql { fetch :iterator1 into :poid, :status };
while(!iterator1.endFetch())
{
System.out.println("poid: " + poid + "Status: "+ status);
#sql { fetch :iterator1 into :poid, :status };
}
Updatable and scrollable iterators
Like JDBC, by default iterators in SQLj are read-only and cannot be moved
backward. To define a scrollable iterator, you need to implement the
sqlj.runtime.Scrollable while defining the iterator. Similar to defining the
updatable cursor, you need to implement sqlj.runtime.ForUpdate while defining
the iterator. Unlike JDBC, when defining the updatable iterator, you also need to
specify the columns you would like to update. Example 5-31 gives the code
snippet, which uses updatable iterators.
Example 5-31 Updatable iterator
#sql public iterator namediterator implements sqlj.runtime.ForUpdate
with (updateColumns="STATUS") (int poid, String status);
namediterator iterator1;
#sql [ctx1] iterator1={ select poid,status from purchaseorder };
while(iterator1.next())
{
System.out.println("before update poid: " + iterator1.poid() +
"Status: "+ iterator1.status());
Search WWH ::




Custom Search