File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes Exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Exception handling" Watch "Exception handling" New topic

Exception handling

annapoorna ch

Joined: Jan 20, 2010
Posts: 4

While running batch jobs i am trying to retrieve some data from one table consists of lacks of records and insert into another table like this
st.executeUpdate("INSERT INTO Table2(source_id,period) SELECT Table1 .RESOURCE_ID, Table1 .period FROM Table1");

but the issue is if exception occurs while inserting a record then the whole job is getting what's requirement is

if exception occurs for a record then i should skip that record and continue the process with remaining records.

is there any solution ?

Thanks in advance

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

I assume you have many Statement.executeUpdate() for this purpose ,

so run every statement.executeUpdate() with in try and catch blocks .

clarify if you dont understand this .

Save India From Corruption - Anna Hazare.
Sandeep Sanaboyina
Ranch Hand

Joined: Dec 14, 2009
Posts: 72
I don't think there will be any direct way to solve that issue. Your best bet is to avoid that exception by first cleaning the data or filtering it before inserting.

Since you are inserting lakhs of records, inserting one record at a time will drastically increase the time taken to complete the job. So, that solution might not work for your case.

They say you have to be the first, the best or different. I say, is it too much to ask for all three.
Martin Vajsar

Joined: Aug 22, 2010
Posts: 3728

If you are on Oracle 10.2 or higher, you could utilize DML error logging, which seems to suit exactly your case. See

wood burning stoves
subject: Exception handling
It's not a secret anymore!