Home > Archive > PostgreSQL JDBC > April 2005 > Is closing a ResulSet, Statement or connection act as a rollback when









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Is closing a ResulSet, Statement or connection act as a rollback when
David Gagnon

2005-04-20, 1:23 pm

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();
}

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com