Michael Paesold wrote:
> I have just wondered about the implementation of Connection.setAutoCommit().
> At least the JDBC 1.3 API has this note:
> NOTE: If this method is called during a transaction, the transaction is
> committed.
Can you point out where in the JDBC specs this is documented. I would
like to look at this some more.
>
> With postgresql that is not the case, at least not for 7.2 of the jdbc
> driver:
>
> public void setAutoCommit(boolean autoCommit) throws SQLException
> {
> if (this.autoCommit == autoCommit)
> return;
> ...
The above is the behavior I would expect, if you have already turned
autocommit on and you attempt to do it again then I would expect a noop.
Of course if the spec says otherwise we should follow the spec.
>
> It think this is important to be consistent, otherwise it's not possible to
> know the transaction state after setAutoCommit()
> Any comments?
You do know the transaction state after setAutoCommit, you will always
be in a transaction.
>
> Another question: is it a generally good idea to start a new transaction
> just after every setAutoCommit(), commit() or rollback()? Wouldn't it be
> better to "begin;" just before the first statement to be executed? That
> wouldn't leave so many open transactions when you have many open
> connections.
But if the open transactions haven't done anything yet then it really
doesn't make any difference.
--Barry