Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


jdbc batch insert exception handling


jdbc batch insert exception handling  using -'java,sql,oracle,jdbc,oracle10g'

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.

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, the remaining records are not getting inserted and the program fails in between.

What I want is even if the 100th record is throwing exception, the remaining insertions should happen as usual before my program ends.

I am not able to understand how to achieve this. Please suggest.

EDIT:

Here is a sample code I am using in my app for batch insert. Assume that the result set has got approx 1000 records.

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();


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 onwards till the end again? How to achieve this?
    

asked Sep 24, 2015 by vijayshukla80
0 votes
4 views



Related Hot Questions



Government Jobs Opening


...