Table of Contents Previous Next


7 Advanced JDBC Connector Functionality : 7.1 Reducing Client-side Resource Requirements

The Advanced Server JDBC driver retrieves the results of a SQL query as a ResultSet object. If a query returns a large number of rows, using a batched ResultSet will:
When you reduce the fetch size of a ResultSet object, the driver doesn’t copy the entire ResultSet across the network (from the server to the client). Instead, the driver requests a small number of rows at a time; as the client application moves through the result set, the driver fetches the next batch of rows from the server.
The Statement object must be created with a ResultSet type of TYPE_FORWARD_ONLY type (which is the default). TYPE_FORWARD_ONLY result sets can only step forward through the ResultSet.
Limiting the batch size of a ResultSet object can speed the retrieval of data and reduce the resources needed by a client-side application. Listing 1.5 creates a Statement object with a batch size limited to five rows.
The call to conn.setAutoCommit(false) ensures that the server won’t close the ResultSet before you have a chance to retrieve the first row. After preparing the Connection, you can construct a Statement object:
For each row in the ResultSet object, the call to println() prints a row was returned.
Remember, while the ResultSet contains all of the rows in the table, they are only fetched from the server five rows at a time. From the client’s point of view, the only difference between a batched result set and an unbatched result set is that a batched result may return the first row in less time.
Next, we will look at another feature (the PreparedStatement) that you can use to increase the performance of certain JDBC applications.

7 Advanced JDBC Connector Functionality : 7.1 Reducing Client-side Resource Requirements

Table of Contents Previous Next