Re: commit and rollback don't throw exceptions when they should - Mailing list pgsql-jdbc

From Oliver Jowett
Subject Re: commit and rollback don't throw exceptions when they should
Date
Msg-id 4AE0164C.5010805@opencloud.com
Whole thread Raw
In response to commit and rollback don't throw exceptions when they should  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
Responses Re: commit and rollback don't throw exceptions when theyshould  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
List 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

pgsql-jdbc by date:

Previous
From: Steve Waldman
Date:
Subject: deadlocks on JDBC batch inserts into tables with many columns
Next
From: David Wall
Date:
Subject: Re: JDBC with PG 8.4 bytea character escaping wire protocol