title: JDBC: Is it better to use executeBatch or executeUpdate to check if each UPDATE statement is successful?
body: <p>I have a MySQL database where I need to do a 1k or so updates, and I am contemplating whether it would be more appropriate to use <code>executeBatch</code> or <code>executeUpdate</code>. The preparedstatement is to be built on an ArrayList of 1k or more ids (which are PKs of the table to be updated). For each update to the table I need to check if it was updated or not (it's possible that the id is not in the table). In the case that the id doesn't exist, I need to add that id to a separate ArrayList which will be used to do batch inserts.</p>
  
  <p>Given the above, is it more appropriate to do:</p>
  
  <ol>
  <li><p>Various separate <code>executeUpdate()</code> and then store the id if it is not updated, or</p></li>
  <li><p>Simply create a batch and use <code>executeBatch()</code>, which will return an array of either a 0 or 1 for each separate statement/id. </p></li>
  </ol>
  
  <p>In case two, the overhead would be an additional array to hold all the 0 or 1 return values. In case one, the overhead would be due to executing each UPDATE separately.</p>