|Oracle8i JDBC Developer's Guide and Reference
Release 3 (8.1.7)
Part Number A83724-01
You can significantly enhance the performance of your JDBC programs by using any of these features:
Auto-commit mode indicates to the database whether to issue an automatic
COMMIT operation after every SQL operation. Being in auto-commit mode can be expensive in terms of time and processing effort if, for example, you are repeating the same statement with different bind variables.
By default, new connection objects are in auto-commit mode. However, you can disable auto-commit mode with the
setAutoCommit() method of the connection object (either
In auto-commit mode, the
COMMIT operation occurs either when the statement completes or the next execute occurs, whichever comes first. In the case of statements returning a
ResultSet, the statement completes when the last row of the
ResultSet has been retrieved or when the
ResultSet has been closed. In more complex cases, a single statement can return multiple results as well as output parameter values. Here, the
COMMIT occurs when all results and output parameter values have been retrieved.
If you disable auto-commit mode with a
setAutoCommit(false) call, then you must manually commit or roll back groups of operations using the
rollback() method of the connection object.
The following example illustrates loading the driver and connecting to the database. Because new connections are in auto-commit mode by default, this example shows how to disable auto-commit. In the example,
conn represents the
Connection object, and
stmt represents the
// Load the Oracle JDBC driver DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver()); // Connect to the database // You can put a database hostname after the @ sign in the connection URL. Connection conn = DriverManager.getConnection ("jdbc:oracle:oci8:@", "scott", "tiger"); // It's faster when auto commit is off conn.setAutoCommit (false); // Create a Statement Statement stmt = conn.createStatement (); ...
Oracle JDBC connection and statement objects allow you to specify the number of rows to prefetch into the client with each trip to the database while a result set is being populated during a query. You can set a value in a connection object that affects each statement produced through that connection, and you can override that value in any particular statement object. The default value in a connection object is 10. Prefetching data into the client reduces the number of round trips to the server.
Similarly, and with more flexibility, JDBC 2.0 allows you to specify the number of rows to fetch with each trip, both for statement objects (affecting subsequent queries) and for result set objects (affecting row refetches). By default, a result set uses the value for the statement object that produced it. If you do not set the JDBC 2.0 fetch size, then the Oracle connection row-prefetch value is used by default.
The Oracle JDBC drivers allow you to accumulate
UPDATE operations of prepared statements at the client and send them to the server in batches. This feature reduces round trips to the server. You can either use Oracle update batching, which typically executes a batch implicitly once a pre-set batch value is reached, or standard update batching, where the batch is executed explicitly.
For a description of the update batching models and how to use them, see "Update Batching".