Re: Connection setAutoCommit()

From: Barry Lind <barry(at)xythos(dot)com>
To: Michael Paesold <mpaesold(at)gmx(dot)at>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Connection setAutoCommit()
Date: 2002-10-11 00:54:41
Message-ID: 3DA62151.3030900@xythos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

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

In response to

Browse pgsql-jdbc by date

  From Date Subject
Next Message Jean-Christian Imbeault 2002-10-11 08:48:10 JDBC driver: Method not implemented
Previous Message Barry Lind 2002-10-11 00:45:09 Re: NullPointer error returned from ResultSet.java