title: Bulk insert in Java using prepared statements batch update
body: <p>I am trying to fill a resultSet in Java with about 50,000 rows of 10 columns
  and then inserting them into another table using the <code>batchExecute</code> method of <code>PreparedStatement</code>.</p>
  
  <p>To make the process faster I did some research and found that while reading data into resultSet the fetchSize plays an important role.</p>
  
  <p>Having a very low fetchSize can result into too many trips to the server and a very high fetchSize can block the network resources, so I experimented a little bit and set up an optimum size that suits my infrastructure.</p>
  
  <p>I am reading this resultSet and creating insert statements to insert into another table of a different database.</p>
  
  <p>Something like this (just a sample, not real code):</p>
  
  <pre><code>for (i=0 ; i&lt;=50000 ; i++) {
      statement.setString(1, "a@a.com");
      statement.setLong(2, 1);
      statement.addBatch();
  }
  statement.executeBatch();
  </code></pre>
  
  <ul>
  <li>Will the executeBatch method try to send all the data at once ?</li>
  <li>Is there a way to define the batch size?</li>
  <li>Is there any better way to speed up the process of bulk insertion?</li>
  </ul>
  
  <p>While updating in bulk (50,000 rows 10 cols), is it better to use a updatable <code>ResultSet</code> or PreparedStaement with batch execution?</p>