pg.ddx.io pgsql-jdbc@postgresql.org mailing list archive
help / color / mirror / Atom feedIs closing a ResulSet, Statement or connection act as a rollback when a transaction is not commited? Not clear in JavaDoc.
2+ messages / 2 participants
[nested] [flat]
* Is closing a ResulSet, Statement or connection act as a rollback when a transaction is not commited? Not clear in JavaDoc.
@ 2005-04-20 18:02 David Gagnon <dgagnon@siunik.com>
0 siblings, 1 reply; 2+ messages in thread
From: David Gagnon @ 2005-04-20 18:02 UTC (permalink / raw)
To: ; +Cc: pgsql-jdbc
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();
}
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Is closing a ResulSet, Statement or connection act as
@ 2005-04-20 23:23 Oliver Jowett <oliver@opencloud.com>
parent: David Gagnon <dgagnon@siunik.com>
0 siblings, 0 replies; 2+ messages in thread
From: Oliver Jowett @ 2005-04-20 23:23 UTC (permalink / raw)
To: David Gagnon <dgagnon@siunik.com>; +Cc: pgsql-jdbc
David Gagnon wrote:
> 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.
Closing ResultSet objects has no effect on transactions. Closing
Connection objects does.
The PostgreSQL driver implements this behaviour: if autocommit is false,
changes in the current transaction are committed only when you call
Connection.commit() or Connection.setAutoCommit(). So closing the
connection does cause a rollback, since that connection is then dead and
can't be committed.
-O
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-04-20 23:23 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-04-20 18:02 Is closing a ResulSet, Statement or connection act as a rollback when a transaction is not commited? Not clear in JavaDoc. David Gagnon <dgagnon@siunik.com>
2005-04-20 23:23 ` Re: Is closing a ResulSet, Statement or connection act as Oliver Jowett <oliver@opencloud.com>
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