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
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.