Batch Updates using JDBC 2.0

Dear all,

I am trying to use a PreparedStatment's batchUpdate() method. Here is the problem.

I get an exception if there is a duplicate entry, and that blows up the entire batch. This leaves me with no room for error checking as to where this error had occurred.

How do I know at which row I got the error? How can I make the batchUpdate() execution to ignore the error and continue?

Thanks,

-rrvvg

[436 byte] By [rrvvg_1976a] at [2007-11-26 23:00:04]
# 1
Maybe catch the exception ?
ReggieBEa at 2007-7-10 13:05:56 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 2

Catching the exception would only tell me what the exception is. And it is clearly stating that is a unique constraint exception.

The problem is, how would I know which row was responsible for this?

Suppose I have a file with 5 records, and the 4th record is a duplicate of an already existing record in the DB. The exception that I catch is clearly stating that I got a unique key problem, but it does not tell me that it was indeed the 4th record that has caused the problem.

Thanks,

-rrvvg

rrvvg_1976a at 2007-7-10 13:05:56 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 3
Could you show me some sourcecode ?
ReggieBEa at 2007-7-10 13:05:56 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 4

This is a case where reading the Java documentation will help you. Here is the link to

int[] executeBatch() throws SQLException.

http://java.sun.com/j2se/1.5.0/docs/api/java/sql/Statement.html#executeBatch()

I know this isn't code showing you how to do it, but I think it does a good job of explaining how to handle your situation. The documentation clearly states that you also need to see the documentation of your specific JDBC driver because Exception behavior is defined by the driver and can be different between vendor offerings..

WorkForFooda at 2007-7-10 13:05:56 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...
# 5
Thanks all...-rrvvg
rrvvg_1976a at 2007-7-10 13:05:56 > top of Java-index,Database Connectivity,Java Database Connectivity (JDBC)...