Return-Path: Delivered-To: apmail-db-derby-dev-archive@www.apache.org Received: (qmail 21709 invoked from network); 15 Dec 2004 07:07:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 15 Dec 2004 07:07:25 -0000 Received: (qmail 87575 invoked by uid 500); 15 Dec 2004 07:07:24 -0000 Delivered-To: apmail-db-derby-dev-archive@db.apache.org Received: (qmail 87519 invoked by uid 500); 15 Dec 2004 07:07:23 -0000 Mailing-List: contact derby-dev-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: list-post: List-Id: Reply-To: "Derby Development" Delivered-To: mailing list derby-dev@db.apache.org Received: (qmail 87498 invoked by uid 99); 15 Dec 2004 07:07:23 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FORGED_RCVD_HELO X-Spam-Check-By: apache.org Received-SPF: neutral (hermes.apache.org: local policy) Received: from e6.ny.us.ibm.com (HELO e6.ny.us.ibm.com) (32.97.182.146) by apache.org (qpsmtpd/0.28) with ESMTP; Tue, 14 Dec 2004 23:07:18 -0800 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by e6.ny.us.ibm.com (8.12.10/8.12.10) with ESMTP id iBF77F6q003973 for ; Wed, 15 Dec 2004 02:07:15 -0500 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay04.pok.ibm.com (8.12.10/NCO/VER6.6) with ESMTP id iBF77Fls268890 for ; Wed, 15 Dec 2004 02:07:15 -0500 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.12.11/8.12.11) with ESMTP id iBF77FT7012867 for ; Wed, 15 Dec 2004 02:07:15 -0500 Received: from Remulak.Net (sig-9-48-111-144.mts.ibm.com [9.48.111.144]) by d01av02.pok.ibm.com (8.12.11/8.12.11) with ESMTP id iBF77EuO012844 for ; Wed, 15 Dec 2004 02:07:14 -0500 Message-ID: <41BFE202.2FABF0B4@Remulak.Net> Date: Tue, 14 Dec 2004 23:04:34 -0800 From: Mamta Satoor X-Mailer: Mozilla 4.75 [en] (Windows NT 5.0; U) X-Accept-Language: en MIME-Version: 1.0 To: derby-dev@db.apache.org Subject: Question about autocommit on and JDBC updatable resultset apis Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Hi, Just a liitle background : For positioned update/deletes using SQL, Derby requires that the application should have autocommit off. This is so that the cursor is not closed before the positioned statements against it. My initial thinking for JDBC 2.0 updatable resultsets was that the applications do not need autocommit off since the update/delete issued by updateRow/deleteRow under the covers will go directly to the parser and hence there will be no commit issued by the JDBC layer and the updatable resultset object will continue to stay open. All this is well and good as long as there are no SQL exceptions. Consider following example where there is an updatable resultset open on a table, and another statement tries to drop that table. con.setAutoCommit(true); s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); rs = s.executeQuery("SELECT c11 FROM t1 FOR UPDATE"); rs.next(); System.out.println("Opened an updatable resultset against t1. Now try to drop table t1 through another Statement"); stmt1 = con.createStatement(); try { stmt1.executeUpdate("drop table t1"); System.out.println("FAIL!!! drop table should have failed because the updatable resultset is still open"); } catch (SQLException e) { if (e.getSQLState().equals("X0X95")) System.out.println("expected exception " + e.getMessage()); else System.out.println("Unexpected exception " + e.getMessage()); } System.out.println("Continue with the deleteRow on the updatable ResultSet object"); rs.deleteRow(); deleteRow finds that rs is in closed state, The rs object got closed by the earlier drop table failure. The severity of the drop table exception was STATEMENT_SEVERITY only but since autocommit is on, impl.jdbc.TransactionResourceImpl.java, in its handleException code raises the severity to TRANSACTION_SEVERITY. Because of the raised severity, the updatable resultset is closed as part of the clean up work. And that is why deleteRow() finds resultset as closed and it throws an exception that cursor is closed. I think this might be confusing for the Derby user. I think they would not expect the drop table failure to close the updatable resultset. So, should we require that autocommit be off for JDBC updatable resultset apis? Or should we just make sure that this behavior is documented well. BTW, If autocommit was set to off for the test case above, the drop table exception severity will not get upgraded to TRANSACTION_SEVERITY and hence updatable resultset object will not be touched by the exception cleanup code. thanks, Mamta