X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5805853FE6 for ; Wed, 20 Apr 2005 14:58:31 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 95233-07 for ; Wed, 20 Apr 2005 17:58:22 +0000 (GMT) Received: from relais.videotron.ca (relais.videotron.ca [24.201.245.36]) by svr1.postgresql.org (Postfix) with ESMTP id 6EA2452A2F for ; Wed, 20 Apr 2005 14:58:21 -0300 (ADT) Received: from [192.168.1.100] ([24.202.23.128]) by VL-MO-MR007.ip.videotron.ca (iPlanet Messaging Server 5.2 HotFix 1.21 (built Sep 8 2003)) with ESMTP id <0IF900J89B9AUW@VL-MO-MR007.ip.videotron.ca> for pgsql-jdbc@postgresql.org; Wed, 20 Apr 2005 13:58:22 -0400 (EDT) Date: Wed, 20 Apr 2005 14:02:19 -0400 From: David Gagnon Subject: Is closing a ResulSet, Statement or connection act as a rollback when a transaction is not commited? Not clear in JavaDoc. In-reply-to: <42667C72.9070708@siunik.com> Cc: pgsql-jdbc@postgresql.org Message-id: <4266992B.2080901@siunik.com> MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7BIT X-Accept-Language: en-us, en User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) References: <4265A05C.6050302@opencloud.com> <42667C72.9070708@siunik.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.012 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/100 X-Sequence-Number: 12707 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(); }