title: How to split a resultset in Java into chunks (500 rows each) without looping?
body: <p>I have a query which returns millions of records which are held in a result set. I have to process (insert/update) these records.  Instead of inserting all the record at once I would like to split the the resultset into chunks of 500 records each and store in an <code>ArrayList</code> or <code>Vector</code> and process these 500 records at a time. </p>
  
  <p>How do I split the resultset into chunks &amp; store in an <code>ArrayList</code> or <code>Vector</code>  without looping through the million records? </p>
  
  <p>i found the answer , got to use CachedRowSet instead of resultset. and use set setPageSize </p>
  
  <pre><code>CachedRowSet crs = new CachedRowSetImpl(); 
  crs.setPageSize(500); 
  crs.execute(conHandle); 
  </code></pre>
  
  <p>and then use </p>
  
  <pre><code>  while(crs.nextPage()) {
  
          collection obj = crs.toCollections();
   }
  </code></pre>
  
  <p>this would ensure that a we could process large data into smaller chunks</p>
  
  <p>but i have a dought here how would the crs populate by passing a connection object where do mention the query string ??</p>