title: JDBC Batch insert exception handling
body: <p>I am performing a JDBC batch insert (inserting 1000 rows approx at a time) each time my program is executed. But i am not able to handle the exception thrown by some of the records properly.</p>
  
  <p>Suppose, the 100th record out of 1000 records is throwing an exception because of an invalid data or size of some value exceeds the column size. Once the exception has occured, <em>the remaining records are not getting inserted</em> and the program fails in between.</p>
  
  <p>What I want is even if the 100th record is throwing exception, the remaining insertions should happen as usual before my program ends. </p>
  
  <p>I am not able to understand how to achieve this. Please suggest.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Here is a sample code I am using in my app for batch insert. Assume that the result set has got approx 1000 records.</p>
  
  <pre><code>PreparedStatement ps = null;
  while(rs.next()){
    //Retrieve the value and set it to a Prepared statement
  
    String name = rs.getString("Name");
    int age = rs.getInt("Age");
    ps.setInt(1, age);
    ps.setString(2, name);
  
    //Finally invoke addBatch
    ps.addBatch();
  }
  
  //Finally call the executeBatch method
  ps.executeBatch();
  </code></pre>
  
  <p>If the 100th record is throwing an exception, then I want to trigger the process only from the 100th too 1000th record. Is there some way to do this such that I can restart the process from the record which threw exception <strong>onwards</strong> till the end again? How to achieve this?</p>