Databases Reference
In-Depth Information
if(iterator1.status().toUpperCase().compareTo("UNSHIPPED")==0)
#sql [ctx1] {update purchaseorder set status=
'shipped' where current of :iterator1 };
}
#sql [ctx1] {commit};
Similarly, you can define the holdability of the iterator by adding the clause
with (holdability=true) while defining the iterator.
5.12.4 Batch updates with SQLj
SQLj supports batch updates the same way JDBC does. But unlike JDBC, SQLj
allows you to add statements of different types (a different instance of the same
statement, or a statement with a host expression) in the same batch.
To create a batch in SQLj, an ExecutionContext is required. The batching can be
enabled by calling setBatching method of ExecutionContext and setting the value
to true .
The number of statements in the batch can be limited to a value by calling the
method setBatchLimit of the ExecutionContext. Once this limit is set, batch will
be automatically executed when this limit is reached. Batch can be explicitly
executed by calling the executeBatch method of the ExecutionContext. Apart
from that, a batch is executed implicitly if the batch contains a statement, which is
incompatible with other statements in the same batch. In that case, a batch will
be executed and a new batch is created for incompatible statements.
Example 5-32 shows how to perform batch update.
Example 5-32 Batch updates
ExecutionContext ec=ctx1.getExecutionContext();
ec.setBatching(true);
#sql[ctx1] { insert into product(pid, price) values('100-201-03',10) };
#sql[ctx1] {update purchaseorder set status='shipped' where poid=5000};
#sql[ctx1] {Delete from purchaseorder where poid=5010};
ec.executeBatch();
System.out.println("Batch executed");
ec.setBatching(false);
When an error occurs while executing any of the batch statements, the remaining
statements are executed and a BatchUpdateException is thrown after all of the
statements have executed.
Search WWH ::




Custom Search