Pre Exam Test Practice
Ask a Question
Advertise on boostr.in
Organizational Research By
Surprising Reserch 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.
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;
¬†¬†//Retrieve the value and set it to a Prepared statement
¬†¬†String name = rs.getString("Name");
¬†¬†int age = rs.getInt("Age");
¬†¬†//Finally invoke addBatch
//Finally call the executeBatch method
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?
Sep 29, 2015
to add a comment.
Related Hot Questions
Government Jobs Opening