From: David Gagnon <dgagnon@siunik.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Is closing a ResulSet, Statement or connection act as a rollback when a transaction is not commited? Not clear in JavaDoc.
Date: Wed, 20 Apr 2005 14:02:19 -0400
Message-ID: <4266992B.2080901@siunik.com> (raw)
In-Reply-To: <42667C72.9070708@siunik.com>
References: <Pine.LNX.4.44.0504110519590.13042-200000@ns.surfnonstop.com>
<4265A05C.6050302@opencloud.com>
<42667C72.9070708@siunik.com>
Hi all,
I use the following code when accessing Postgreql. I suspect it may
have a weakness if an exception (Not SQLException) is thrown in the
try/catch block. I got a NullPointerException today so with the
following code there is no rollback on the trasaction but the
ResultSet/Connection/Statement will be closed (in finally block). Is
that oki? I will probably change the catch (SQLException e) for a catch
(Exception e). I just wanted to be sure since it's not clear in the
javadoc that closing a uncomitted resultSet is the samething as issuing
a rollback prior to closing the ResultSet.
Thanks for your help!! It's really appreciated
/David
try {
dbCon = ConnectionFactory.getConnection();
dbCon.startTransaction();
...
Throws NullPointerException...
...
dbCon.commitTransaction();
} catch (SQLException e) {
log.error("Problem with the db : " + e.getMessage(), e);
try {
dbCon.rollbackTransaction();
} catch (SQLException e1) {
log.error("Unable to rollback : " + e1.getMessage(), e);
}
ExceptionAdaptor.instance().getMappedException(e, "Unable to
add : " + e.getMessage(), true, ExceptionAdaptor.ACTION_INSERT);
} finally {
if (dbCon != null)
dbCon.closeAll();
}
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: dgagnon@siunik.com
Subject: Re: Is closing a ResulSet, Statement or connection act as a rollback when a transaction is not commited? Not clear in JavaDoc.
In-Reply-To: <4266992B.2080901@siunik.com>
References: <Pine.LNX.4.44.0504110519590.13042-200000@ns.surfnonstop.com> <4265A05C.6050302@opencloud.com> <42667C72.9070708@siunik.com> <4266992B.2080901@siunik.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox