Subject Re: [Firebird-Java] Re: No SavePoints for FB 1.0x?
Author Roman Rokytskyy
> Thanks Roman but I'm not sure I understand this, the BEGIN..END
> looks null to me.

> WHEN SQLCODE -803 DO BEGIN
> END;

And it should be "null". :) The SQLCODE -803 is "duplicate key exception",
and you want to ignore it, right?

> Just out of curiosity and moving on from the stored procedure, what
> is the behavior if I did this?
>
> for ( Iterator it = records.iterator(); it.hasNext(); )
> {
> Record record = it.next();
>
> try
> {
> insertIntoOneTable( con, record );
> }
> catch ( DuplicateKeyException e )
> {
> // just continue
> }
> }
>
> con.commit();
>
> public void insertIntoOneTable( con, record ) throws ...
> {
> // this just does an insert into a single table
> }
>
> What would happen here?

If you're handling the DuplicateKeyException in your application, what's the
point to have savepoints? Each duplicate key invalidates only that insert,
not the inserts done previously. You can successfully continue your batch
(but not in the JDBC sense - java.sql.Statement or
java.sql.PreparedStatement batches are automatically rolled back).

So, that's your choice whether to wait for error code for failed insert on
the client or use stored procedure that simply ignores that error. In case
of procedure your call will always succeed.

Roman