Subject Re: autocommit mode
Author Roman Rokytskyy
Hi,

> Let's suppose I set autoCommit(true) and execute a SQL statement
> which fires a trigger in my database. The trigger tries to make some
> updates in a table. After some registers are successfully updated,
> it fails because a primary key constraint. So the java application
> receives a SQLException.

All changes made by a trigger are discarded by the server internally
in case of error. However, I do not know what happens if multiple
triggers are fired for one statement. In theory _all_ changes should
be discarded.

> In this situation, am I expected to do conn.rollback() in the catch
> block, to ensure every updated register is conveniently rolled back,
> or is this opertation automatically perfomed because of the
> autocommit mode?

According to the specification you are not allowed to execute commit()
or rollback() when auto-commit is on. You will get an exception in
this case.

> So the general question could be: what happens after a SQL error
> occurs and autocommit mode is switched on?

In general it is quite interesting question... Transaction should be
rolled back. Driver is relatively simple here. It tries to commit
transaction, if commit fails, it performes rollback (probably we can
simply rollback tx in auto-commit case). So, it is the responsibility
of the database server to _not allow_ transaction to be committed. I
am almost 100% sure that in scenario described above transaction will
be rolled back.

Best regards,
Roman Rokytskyy