O'Reilly logo

Java Programming with Oracle SQLJ by Jason Price

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

10.2. Batch Processing

The technique of combining many small operations together into one large batch has a proud heritage in computing, and dates all the way back to the time when jobs were submitted to computers in the form of punched cards. You will be pleased to know that SQLJ has similar facilities for batching database operations.

You can get SQLJ to buffer identical SQL INSERT, UPDATE, or DELETE statements in your SQLJ programs into a batch, which is then submitted to the database. This reduces the number of round trips made to the database over the network, and may lead to an improvement in performance.

A SQLJ program may only take advantage of batching when the same SQL statement is run repeatedly.

One candidate for batching is a SQL statement contained within a loop. Another is a method that is run repeatedly and contains a SQL statement. In this section, I explain how to control and run batches in your SQLJ programs.

10.2.1. Controlling Batching

Batching is a feature you control through an execution context. (Execution contexts were discussed in Chapter 8.) By default, batching is not enabled. To enable batching for an execution context, call the method setBatching( ). This method accepts a Boolean true or false value indicating whether or not batching should be enabled. The following statements first create an execution context named my_exec_context, and then ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required