Re: commit and rollback don't throw exceptions when they should

From: Oliver Jowett <oliver(at)opencloud(dot)com>
To: taktos <taktos(at)gmail(dot)com>
Cc: Kevin Grittner <Kevin(dot)Grittner(at)wicourts(dot)gov>, pgsql-jdbc(at)postgresql(dot)org
Subject: Re: commit and rollback don't throw exceptions when they should
Date: 2009-10-22 08:22:36
Message-ID: 4AE0164C.5010805@opencloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

taktos wrote:
> I made a groovy code that tests whether Connection#commit() throws
> excepton when connection has been closed.
>
> http://github.com/taktos/JDBC-Driver-Test/blob/master/ConnectionTest.groovy
>
> I tested in environment below:
> Oracle 10g XE (ojdbc14.jar and ojdbc6.jar)
> MySQL 5.1 (mysql-connector-java-5.1.10.jar)
> h2database (h2-1.2.121.jar)
> PostgreSQL 8.3 (postgresql-8.3.605.jdbc4.jar)
>
> Drivers other than PosrgreSQL throws exception as I had expected, but
> PostgreSQL didn't throw exception.

Yes, that is the case I mentioned where there have been no commands
executed in the transaction. In that case, the driver has no work to do
on commit() so it does not notice the connection was closed.

Even if we added a check for an explicit Connection.close() call before
Connection.commit(), that would not help with your test where you are
shutting down the server. The driver will only notice the network
connection is gone when it next tries to actually send or receive data.

Try adding a simple query ("SELECT 1", or whatever) to your test, and
you should see an exception on close.

-O

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message David Wall 2009-10-22 15:59:54 Re: JDBC with PG 8.4 bytea character escaping wire protocol
Previous Message taktos 2009-10-22 07:00:38 Re: commit and rollback don't throw exceptions when they should