File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Exception handling" Watch "Exception handling" New topic
Author

Exception handling

annapoorna ch
Greenhorn

Joined: Jan 20, 2010
Posts: 4
Hi

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 stopped.so 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
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

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

http://download.oracle.com/docs/cd/B19306_01/server.102/b14220/sqlplsql.htm#sthref3393
http://download.oracle.com/docs/cd/B19306_01/server.102/b14231/tables.htm#ADMIN10261

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception handling