You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2006/08/18 02:47:42 UTC

svn commit: r432450 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi: ConcurrencyTest.java HoldabilityTest.java SURQueryMixTest.java SURTest.java

Author: djd
Date: Thu Aug 17 17:47:41 2006
New Revision: 432450

URL: http://svn.apache.org/viewvc?rev=432450&view=rev
Log:
DERBY-1555 DERBY-1701 (partial) Change the tests that extend SURBaseTest to use the utilitiy methods
rather than the con field from SURBaseTest to fit into the generic single connection model provided
by BaseJDBCTestCase. Incremental development, next step will be to remove the con field from SURBaseTest.

Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURQueryMixTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java?rev=432450&r1=432449&r2=432450&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/ConcurrencyTest.java Thu Aug 17 17:47:41 2006
@@ -41,24 +41,18 @@
     public void setUp() 
         throws Exception 
     {      
-        try {
-            super.setUp();
-        } catch (SQLException e) {
-            if (con!=null) tearDown();
-            throw e;
-        }
         // For the concurrency tests, we recreate the model
         // for each testcase (since we do commits)
         SURDataModelSetup.createDataModel
-            (SURDataModelSetup.SURDataModel.MODEL_WITH_PK, con);
-        con.commit();
+            (SURDataModelSetup.SURDataModel.MODEL_WITH_PK, getXConnection());
+        commit();
     }
     
     public void tearDown() throws Exception 
     {
         try {
-            con.rollback();
-            Statement dropStatement = con.createStatement();
+            rollback();
+            Statement dropStatement = createStatement();
             dropStatement.execute("drop table t1");
             dropStatement.close();
         } catch (SQLException e) {
@@ -75,7 +69,7 @@
     public void testUpdateLockDownGrade1()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1 for update");
         
@@ -99,6 +93,11 @@
             con2.rollback();
         }
         assertTrue("Expected Derby to hold updatelocks in RR mode", false);
+        
+        s2.close();
+        con2.close();
+        
+        s.close();
     }
     
     /**
@@ -108,7 +107,7 @@
     public void testAquireUpdateLock1()
         throws SQLException 
     {
-        Statement s = con.createStatement();
+        Statement s = createStatement();
         ResultSet rs = s.executeQuery("select * from t1");
         
         // After navigating through the resultset, 
@@ -126,6 +125,10 @@
         } finally {
             con2.rollback();
         }
+        
+        s2.close();
+        con2.close();
+        s.close();
     }
     
     /*
@@ -135,7 +138,7 @@
     public void testSharedLocks1()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_READ_ONLY);
         final ResultSet rs = s.executeQuery("select * from t1");
         scrollForward(rs);
@@ -150,6 +153,8 @@
             con2.rollback();
             con2.close();
         }
+        
+        s.close();
     }
     
     /*
@@ -159,7 +164,7 @@
     public void testSharedLocks2()
         throws SQLException 
     {
-        Statement s = con.createStatement();
+        Statement s = createStatement();
         ResultSet rs = s.executeQuery("select * from t1");
         scrollForward(rs);
         Connection con2 = getNewConnection();
@@ -172,6 +177,7 @@
             con2.rollback();
             con2.close();
         }
+        s.close();
     }
     
     /*
@@ -180,7 +186,7 @@
      **/
     public void testSharedAndUpdateLocks1()
         throws SQLException {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         
         ResultSet rs = s.executeQuery("select * from t1");
@@ -196,6 +202,7 @@
             con2.rollback();
             con2.close();
         }
+        s.close();
     }
     
     /*
@@ -206,7 +213,7 @@
     public void testSharedAndUpdateLocks2()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1 for update");
         scrollForward(rs);
@@ -221,6 +228,7 @@
             con2.rollback();
             con2.close();
         }
+        s.close();
     }
     
     /**
@@ -232,8 +240,8 @@
     public void testUpdatePurgedTuple1()
         throws SQLException
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next();
@@ -294,7 +302,7 @@
         println("T1: updateInt(2, 3);");
         rs.updateRow();
         println("T1: updateRow()");
-        con.commit();
+        commit();
         println("T1: commit");
         rs = s.executeQuery("select * from t1");
         println("T3: select * from table");
@@ -304,6 +312,9 @@
                     rs.getInt(3) + ")");
             
         }
+        
+        con2.close();
+        s.close();
     }
     
     /**
@@ -313,8 +324,8 @@
     public void testUpdatePurgedTuple2()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next(); // Point to first tuple
@@ -346,14 +357,14 @@
                 rs.getInt(2) + "," +
                 rs.getInt(3) + ")");
         
-        PreparedStatement ps = con.prepareStatement
+        PreparedStatement ps = prepareStatement
             ("update T1 set a=? where current of " + rs.getCursorName());
         ps.setInt(1, 3);
         int updateCount = ps.executeUpdate();
         println("T1: update table, set a=3 where current of " + 
                 rs.getCursorName());
         println("T1: commit");
-        con.commit();
+        commit();
         rs = s.executeQuery("select * from t1");
         while (rs.next()) {
             println("T3: Tuple:(" + rs.getInt(1) + "," +
@@ -361,6 +372,8 @@
                     rs.getInt(3) + ")");
             
         }
+        
+        con2.close();
     }
     
     /**
@@ -370,8 +383,8 @@
     public void testUpdatePurgedTuple3()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next(); // Point to first tuple
@@ -426,7 +439,7 @@
         rs.updateRow();
         println("T1: updated column 2, to value=3");
         println("T1: commit");
-        con.commit();
+        commit();
         rs = s.executeQuery("select * from t1");
         while (rs.next()) {
             println("T5: Read Tuple:(" + rs.getInt(1) + "," +
@@ -434,6 +447,8 @@
                     rs.getInt(3) + ")");
             
         }
+        
+        con2.close();
     }
     
     /**
@@ -443,8 +458,8 @@
     public void testUpdatePurgedTuple4()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next(); // Point to first tuple
@@ -511,7 +526,7 @@
         rs.updateRow();
         println("T1: updated column 2, to value=3");
         println("T1: commit");
-        con.commit();
+        commit();
         rs = s.executeQuery("select * from t1");
         while (rs.next()) {
             println("T4: Read next Tuple:(" + rs.getInt(1) + "," +
@@ -528,8 +543,8 @@
     public void testUpdateModifiedTuple1()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next(); // Point to first tuple
@@ -564,7 +579,7 @@
         rs.updateInt(2, 3);
         rs.updateRow();
         println("T1: updated column 2, to value=3");
-        con.commit();
+        commit();
         println("T1: commit");
         rs = s.executeQuery("select * from t1");
         while (rs.next()) {
@@ -582,8 +597,8 @@
     public void testUpdateModifiedTuple2()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next(); // Point to first tuple
@@ -618,7 +633,7 @@
         rs.updateInt(3, 9999);
         rs.updateRow();
         println("T1: updated column 3, to value=9999");
-        con.commit();
+        commit();
         println("T1: commit");
         rs = s.executeQuery("select * from t1");
         while (rs.next()) {
@@ -637,8 +652,8 @@
     public void testTableIntentLock1()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         println("T1: select * from t1");
         ResultSet rs = s.executeQuery("select * from t1 for update");
@@ -678,8 +693,8 @@
     public void testUpdateLockInReadUncommitted()
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next();
@@ -701,7 +716,9 @@
                          e.getSQLState());
         } finally {
             con2.rollback();
-        }          
+        }
+        con2.close();
+        s.close();
     }
     
     /**
@@ -731,8 +748,8 @@
                                         boolean testTruncate)
         throws SQLException 
     {
-        con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
-        Statement delStatement = con.createStatement();
+        getXConnection().setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
+        Statement delStatement = createStatement();
         // First delete all records except the last and first
         int deleted = delStatement.executeUpdate
             ("delete from T1 where id>0 and id<" + (recordCount-1));
@@ -740,10 +757,10 @@
         println("T1: delete records");
         assertEquals("Invalid number of records deleted", expectedDeleted, 
                      deleted);
-        con.commit();
+        commit();
         println("T1: commit");
         
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next();
@@ -798,7 +815,7 @@
         println("T1: updateInt(2, 3);");
         rs.updateRow();
         println("T1: updateRow()");
-        con.commit();
+        commit();
         println("T1: commit");
         rs = s.executeQuery("select * from t1");
         println("T4: select * from table");

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java?rev=432450&r1=432449&r2=432450&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/HoldabilityTest.java Thu Aug 17 17:47:41 2006
@@ -21,6 +21,8 @@
 import junit.framework.*;
 import java.sql.*;
 
+import org.apache.derbyTesting.functionTests.util.CleanDatabaseTestSetup;
+
 /**
  * Tests holdable resultsets.
  */
@@ -40,7 +42,7 @@
         
         suite.addTestSuite(HoldabilityTest.class);
         
-        return suite;
+        return new CleanDatabaseTestSetup(suite);
 
     }
 
@@ -50,21 +52,15 @@
     public void setUp() 
         throws Exception 
     {      
-        try {
-            super.setUp();
-        } catch (SQLException e) {
-            if (con!=null) tearDown();
-            throw e;
-        }
-        // For the holdability tests, we recreate the model
+       // For the holdability tests, we recreate the model
         // for each testcase (since we do commits)
         
         // We also use more records to ensure that the disk
         // is being used.
         SURDataModelSetup.createDataModel
-            (SURDataModelSetup.SURDataModel.MODEL_WITH_PK, con,
+            (SURDataModelSetup.SURDataModel.MODEL_WITH_PK, getXConnection(),
              recordCount);
-        con.commit();
+        commit();
     }
     
     /**
@@ -74,8 +70,8 @@
     public void tearDown() throws Exception 
     {
         try {            
-            con.rollback();
-            Statement dropStatement = con.createStatement();
+            rollback();
+            Statement dropStatement = createStatement();
             dropStatement.execute("drop table t1");
             dropStatement.close();
         } catch (SQLException e) {
@@ -91,12 +87,13 @@
     public void testHeldForwardOnlyResultSetScanInit() 
         throws SQLException
     {
-        Statement s = con.createStatement();
+        Statement s = createStatement();
         ResultSet rs = s.executeQuery(selectStatement);
         
-        con.commit(); // scan initialized
+        commit(); // scan initialized
         
         scrollForward(rs);
+        s.close();
     }
     
     /**
@@ -106,18 +103,19 @@
     public void testHeldForwardOnlyResultSetScanInProgress() 
         throws SQLException
     {
-        Statement s = con.createStatement();
+        Statement s = createStatement();
         ResultSet rs = s.executeQuery(selectStatement);
 
         for (int i=0; i<this.recordCount/2; i++) {
             rs.next();
             verifyTuple(rs);
         }
-        con.commit(); // Scan is in progress
+        commit(); // Scan is in progress
         
         while (rs.next()) {
             verifyTuple(rs);
         }
+        s.close();
     }
 
     /**
@@ -127,13 +125,14 @@
     public void testHeldForwardOnlyUpdatableResultSetScanInit() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
-        con.commit(); // scan initialized
+        commit(); // scan initialized
         rs.next();    // naviagate to a new tuple
         updateTuple(rs); // Updatable
         scrollForward(rs);
+        s.close();
     }
     
     
@@ -145,7 +144,7 @@
     public void testCompressOnHeldForwardOnlyUpdatableResultSetScanInProgress()
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
 
@@ -154,10 +153,11 @@
             verifyTuple(rs);
         }
         updateTuple(rs);
-        con.commit(); // Scan is in progress
+        commit(); // Scan is in progress
         
         // Verifies resultset can do updates after compress
         verifyResultSetUpdatableAfterCompress(rs);
+        s.close();
         
     }
 
@@ -169,13 +169,14 @@
     public void testCompressOnHeldForwardOnlyUpdatableResultSetScanInit() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
-        con.commit(); // scan initialized
+        commit(); // scan initialized
         
         // Verifies resultset can do updates after compress
         verifyResultSetUpdatableAfterCompress(rs);
+        s.close();
     }
         
     /**
@@ -185,7 +186,7 @@
     public void testHeldForwardOnlyUpdatableResultSetScanInProgress() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
 
@@ -194,12 +195,13 @@
             verifyTuple(rs);
         }
         updateTuple(rs);
-        con.commit(); // Scan is in progress
+        commit(); // Scan is in progress
         rs.next();
         updateTuple(rs); // Still updatable
         while (rs.next()) {
             verifyTuple(rs); // complete the scan
         }
+        s.close();
     }
     
     /**
@@ -209,14 +211,16 @@
     public void testHeldScrollableResultSetScanInit() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_READ_ONLY);
         ResultSet rs = s.executeQuery(selectStatement);
         
-        con.commit(); // scan initialized
+        commit(); // scan initialized
         
         scrollForward(rs);
         scrollBackward(rs);
+        
+        s.close();
     }
         
     /**
@@ -226,7 +230,7 @@
     public void testHeldScrollableResultSetScanInProgress() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_READ_ONLY);
         ResultSet rs = s.executeQuery(selectStatement);
 
@@ -234,12 +238,13 @@
             rs.next();
             verifyTuple(rs);
         }
-        con.commit(); // Scan is in progress
+        commit(); // Scan is in progress
         
         while (rs.next()) {
             verifyTuple(rs);
         }
         scrollBackward(rs);
+        s.close();
     }
 
     /**
@@ -249,15 +254,16 @@
     public void testHeldScrollableResultSetScanDone() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_READ_ONLY);
         ResultSet rs = s.executeQuery(selectStatement);
         
         scrollForward(rs); // Scan is done
         
-        con.commit();
+        commit();
         
         scrollBackward(rs);
+        s.close();
     }
 
     /**
@@ -267,7 +273,7 @@
     public void testHeldScrollableUpdatableResultSetScanInit() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         
@@ -275,10 +281,12 @@
             assertTrue("ResultSet concurrency downgraded to CONCUR_READ_ONLY",
                        false);
         }
-        con.commit(); // scan initialized
+        commit(); // scan initialized
         
         scrollForward(rs);
         scrollBackwardAndUpdate(rs);
+        
+        s.close();
     }    
     
     /**
@@ -288,7 +296,7 @@
     public void testHeldScrollableUpdatableResultSetScanInProgress() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         if (rs.getConcurrency()==ResultSet.CONCUR_READ_ONLY) {
@@ -299,12 +307,14 @@
             rs.next();
             verifyTuple(rs);
         }
-        con.commit(); // Scan is in progress
+        commit(); // Scan is in progress
         
         while (rs.next()) {
             verifyTuple(rs);
         }
         scrollBackwardAndUpdate(rs);
+        
+        s.close();
     }
 
     /**
@@ -314,7 +324,7 @@
     public void testHeldScrollableUpdatableResultSetScanDone() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         
@@ -325,9 +335,11 @@
       
         scrollForward(rs); // Scan is done
         
-        con.commit();
+        commit();
         
         scrollBackwardAndUpdate(rs);
+        
+        s.close();
     }
 
     /**
@@ -337,7 +349,7 @@
     public void testUpdateRowAfterCommitOnHeldForwardOnlyResultSet() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         
@@ -346,7 +358,7 @@
                        false);
         }
         rs.next();
-        con.commit();
+        commit();
         try {
             rs.updateInt(2, -100);
             rs.updateRow();
@@ -355,6 +367,7 @@
             assertEquals("Unexpected SQLState",
                          INVALID_CURSOR_STATE_NO_CURRENT_ROW, e.getSQLState());
         }
+        s.close();
     }
 
     /**
@@ -364,7 +377,7 @@
     public void testUpdateRowAfterCommitOnHeldScrollInsensitiveResultSet() 
         throws SQLException
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         
@@ -373,7 +386,7 @@
                        false);
         }
         rs.next();
-        con.commit();
+        commit();
         try {
             rs.updateInt(2, -100);
             rs.updateRow();
@@ -382,6 +395,7 @@
             assertEquals("Unexpected SQLState",
                          INVALID_CURSOR_STATE_NO_CURRENT_ROW, e.getSQLState());
         }
+        s.close();
     }
 
     /**
@@ -393,7 +407,7 @@
         throws SQLException
     {
         // First: Read all records in the table into the ResultSet:
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         
         ResultSet rs = s.executeQuery(selectStatement);
@@ -401,10 +415,12 @@
             assertTrue("ResultSet concurrency downgraded to CONCUR_READ_ONLY",
                        false);
         }
-        con.commit(); // commit
+        commit(); // commit
         
         // Verifies resultset can do updates after compress
         verifyResultSetUpdatableAfterCompress(rs);
+        
+        s.close();
     }
 
     /**
@@ -416,7 +432,7 @@
         throws SQLException
     {
         // First: Read all records in the table into the ResultSet:
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         if (rs.getConcurrency()==ResultSet.CONCUR_READ_ONLY) {
@@ -425,9 +441,11 @@
         }
         rs.next(); // Scan is in progress.
         
-        con.commit(); // commit, releases the lock on the records
+        commit(); // commit, releases the lock on the records
         
         verifyCompressInvalidation(rs);
+        
+        s.close();
     }
     
     /**
@@ -439,7 +457,7 @@
         throws SQLException
     {
         // First: Read all records in the table into the ResultSet:
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery(selectStatement);
         if (rs.getConcurrency()==ResultSet.CONCUR_READ_ONLY) {
@@ -449,9 +467,10 @@
         
         scrollForward(rs); // scan is done
         
-        con.commit(); // commit, releases the lock on the records
+        commit(); // commit, releases the lock on the records
         
         verifyCompressInvalidation(rs);
+        s.close();
     }
 
     /**
@@ -462,19 +481,19 @@
         throws SQLException
     {
                 // Delete all records except the first:
-        Statement delStatement = con.createStatement();
+        Statement delStatement = createStatement();
         int deleted = delStatement.executeUpdate("delete from T1 where id>0");
         int expectedDeleted = recordCount-1;    
         
         assertEquals("Invalid number of records deleted", expectedDeleted, 
                      deleted);
-        con.commit();
+        commit();
         
         // Execute online compress
         onlineCompress(true, true, true);
         
         // Now reinsert the tuples:
-        PreparedStatement ps = con.
+        PreparedStatement ps = 
             prepareStatement("insert into t1 values (?,?,?,?)");
         
         for (int i=0; i<recordCount*2; i++) {
@@ -486,7 +505,7 @@
             ps.addBatch();
         }
         ps.executeBatch();
-        con.commit();
+        commit();
 
         rs.next();
         updateTuple(rs);
@@ -511,10 +530,10 @@
             assertNull("Expected no warning when updating this row", warn);
         }
         
-        con.commit();
+        commit();
         
         // Verify data
-        rs = con.createStatement().executeQuery(selectStatement);
+        rs = createStatement().executeQuery(selectStatement);
         while (rs.next()) {            
             verifyTuple(rs);
         }
@@ -530,19 +549,20 @@
     {
         
         // Delete all records except the first:
-        Statement delStatement = con.createStatement();
+        Statement delStatement = createStatement();
         int deleted = delStatement.executeUpdate("delete from T1 where id>0");
         int expectedDeleted = recordCount-1;    
+        delStatement.close();
         
         assertEquals("Invalid number of records deleted", expectedDeleted, 
                      deleted);
-        con.commit();
+        commit();
         
         // Execute online compress
         onlineCompress(true, true, true);
         
         // Now reinsert the tuples:
-        PreparedStatement ps = con.
+        PreparedStatement ps = 
             prepareStatement("insert into t1 values (?,?,?,?)");
         
         for (int i=0; i<recordCount*2; i++) {
@@ -554,7 +574,8 @@
             ps.addBatch();
         }
         ps.executeBatch();
-        con.commit();
+        ps.close();
+        commit();
         
         // Update last tuple
         rs.last();         
@@ -570,10 +591,10 @@
         updateTuple(rs); 
         warn = rs.getWarnings();
         assertWarning(warn, CURSOR_OPERATION_CONFLICT);
-        con.commit();
+        commit();
         
         // Verify data
-        rs = con.createStatement().executeQuery(selectStatement);
+        rs = createStatement().executeQuery(selectStatement);
         while (rs.next()) {            
             // This will fail if we managed to update reinserted tuple
             verifyTuple(rs); 
@@ -606,6 +627,7 @@
         
         try { 
             ps2.executeUpdate();
+            ps2.close();
             con2.commit();
         } finally {
             con2.close();

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURQueryMixTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURQueryMixTest.java?rev=432450&r1=432449&r2=432450&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURQueryMixTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURQueryMixTest.java Thu Aug 17 17:47:41 2006
@@ -73,13 +73,13 @@
         throws SQLException
     {
         println(query);
-        DatabaseMetaData dbMeta = con.getMetaData();
+        DatabaseMetaData dbMeta = getXConnection().getMetaData();
                 
         if (dbMeta.ownDeletesAreVisible(ResultSet.TYPE_SCROLL_INSENSITIVE)) {
             checkRowDeleted = true;
         }
         
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                           ResultSet.CONCUR_UPDATABLE);
         
         s.setCursorName(cursorName);
@@ -138,6 +138,7 @@
         }
         
         rs.close();
+        s.close();
     }
     
     /**
@@ -233,7 +234,7 @@
             rs.absolute(key.intValue());            
             if (rs.rowDeleted()) continue; // skip deleting row if already deleted
             if (positioned) {
-                con.createStatement().executeUpdate
+                createStatement().executeUpdate
                         ("DELETE FROM T1 WHERE CURRENT OF \"" + cursorName + 
                          "\"");
             } else {
@@ -325,7 +326,7 @@
         sb.append(cursorName);
         sb.append("\"");
         println(sb.toString());
-        PreparedStatement ps = con.prepareStatement(sb.toString());
+        PreparedStatement ps = prepareStatement(sb.toString());
         
         for (int column = 1; column<=meta.getColumnCount(); column++) {
            if (meta.getColumnType(column)==Types.INTEGER) {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java?rev=432450&r1=432449&r2=432450&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/jdbcapi/SURTest.java Thu Aug 17 17:47:41 2006
@@ -19,6 +19,8 @@
  */
 package org.apache.derbyTesting.functionTests.tests.jdbcapi;
 import org.apache.derbyTesting.functionTests.util.SQLStateConstants;
+
+import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -40,7 +42,7 @@
     public SURTest(String name) {
         super(name);
     }
-    
+
     /**
      * Test that you get a warning when specifying a query which is not
      * updatable and concurrency mode CONCUR_UPDATABLE.
@@ -49,7 +51,7 @@
     public void testConcurrencyModeWarning1()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1 order by a");
@@ -61,6 +63,7 @@
         assertWarning(warn, QUERY_NOT_QUALIFIED_FOR_UPDATABLE_RESULTSET);
         scrollForward(rs);
         rs.close();
+        s.close();
     }
     
     /**
@@ -71,7 +74,7 @@
     public void testConcurrencyModeWarning2()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery
@@ -85,6 +88,7 @@
         assertWarning(warn, QUERY_NOT_QUALIFIED_FOR_UPDATABLE_RESULTSET);
         scrollForward(rs);
         rs.close();
+        s.close();
     }
     
     /**
@@ -96,7 +100,7 @@
     public void testForUpdateException1()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                           ResultSet.CONCUR_UPDATABLE);
         try {
             String queryString =
@@ -111,7 +115,8 @@
                          FOR_UPDATE_NOT_PERMITTED_SQL_STATE,
                          e.getSQLState());
         }
-        con.rollback();
+        rollback();
+        s.close();
     }
     
     /**
@@ -122,7 +127,7 @@
     public void testForUpdateException2()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                           ResultSet.CONCUR_UPDATABLE);
         try {
             String queryString =
@@ -138,7 +143,8 @@
                          FOR_UPDATE_NOT_PERMITTED_SQL_STATE,
                          e.getSQLState());
         }
-        con.rollback();
+        rollback();
+        s.close();
     }
     
     /**
@@ -148,13 +154,14 @@
     public void testForwardOnlyReadOnly1()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                           ResultSet.CONCUR_READ_ONLY);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1");
         
         scrollForward(rs);
         rs.close();
+        s.close();
     }
     
     
@@ -165,13 +172,14 @@
     public void testFailOnUpdateOfReadOnlyResultSet1()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                           ResultSet.CONCUR_READ_ONLY);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1");
         
         rs.next();
         assertFailOnUpdate(rs);
+        s.close();
     }
     
     /**
@@ -181,13 +189,14 @@
     public void testFailOnUpdateOfReadOnlyResultSet2()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1 order by id");
         
         rs.next();
         assertFailOnUpdate(rs);
+        s.close();
     }
     
     /**
@@ -197,7 +206,7 @@
     public void testFailOnUpdateOfReadOnlyResultSet3()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs =
@@ -205,6 +214,7 @@
         
         rs.next();
         assertFailOnUpdate(rs);
+        s.close();
     }
     
     /**
@@ -214,7 +224,7 @@
     public void testFailOnUpdateOfReadOnlyResultSet4()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery
@@ -223,6 +233,7 @@
         rs.next();
         verifyTuple(rs);
         assertFailOnUpdate(rs);
+        s.close();
     }
     
     
@@ -233,7 +244,7 @@
     public void testFailOnUpdateOfReadOnlyResultSet5()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.
+        Statement s = createStatement(ResultSet.
                                           TYPE_SCROLL_INSENSITIVE,
                                           ResultSet.CONCUR_READ_ONLY);
         s.setCursorName(getNextCursorName());
@@ -243,6 +254,7 @@
         rs.next();
         verifyTuple(rs);
         assertFailOnUpdate(rs);
+        s.close();
     }
 
     /** 
@@ -308,7 +320,7 @@
                                             final int resultSetType) 
         throws SQLException
     {
-        final Statement s = con.createStatement(resultSetType, 
+        final Statement s = createStatement(resultSetType, 
                                                 ResultSet.CONCUR_UPDATABLE);
         final String cursorName = getNextCursorName();
         s.setCursorName(cursorName);
@@ -324,10 +336,10 @@
             rs.absolute(recordToUpdate);
         }
         
-        con.commit();
+        commit();
         
         PreparedStatement ps = 
-            con.prepareStatement("update t1 set a=? where current of " +
+            prepareStatement("update t1 set a=? where current of " +
                                  cursorName);
         // First: check that we get an exception on update without repositioning:
         try {
@@ -362,6 +374,9 @@
             rs.updateRow();
         }
         
+        s.close();
+        ps.close();
+        
     }
 
     /**
@@ -371,7 +386,7 @@
     public void testMultiUpdateRow1() 
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1");
@@ -426,6 +441,7 @@
                    "updateRow and cancelRowUpdates", rs.rowUpdated());
         
         rs.close();
+        s.close();
     }
 
     /**
@@ -435,7 +451,7 @@
     public void testMultiUpdateRow2() 
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1");
@@ -491,6 +507,7 @@
                    "updateRow and cancelRowUpdates", rs.rowUpdated());
         
         rs.close();
+        s.close();
     }
 
     /**
@@ -500,12 +517,12 @@
     public void testCursorOperationConflictWarning1() 
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next();
-        con.createStatement().executeUpdate("delete from t1 where id=" +
+        createStatement().executeUpdate("delete from t1 where id=" +
                                             rs.getString("ID"));
         final int newValue = -3333;
         final int oldValue = rs.getInt(2);
@@ -528,6 +545,7 @@
         assertEquals("Did not expect the resultset to be updated", oldValue, rs.getInt(2));
         
         rs.close();
+        s.close();
     }
 
     /**
@@ -538,18 +556,18 @@
     public void testCursorOperationConflictWarning2() 
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1");
         rs.next();
-        con.createStatement().executeUpdate ("delete from t1 where id=" +
+        createStatement().executeUpdate ("delete from t1 where id=" +
                                              rs.getString("ID"));
         
         final int newValue = -3333;
         final int oldValue = rs.getInt(2);
         
-        Statement s3 = con.createStatement();
+        Statement s3 = createStatement();
         int updateCount = s3.executeUpdate
             ("update t1 set A=" + newValue + 
              " where current of " + rs.getCursorName());
@@ -562,7 +580,7 @@
         assertEquals("Did not expect the resultset to be updated", oldValue, rs.getInt(2));
         assertEquals("Expected update count to be 0", 0, updateCount);
         
-        Statement s4 = con.createStatement();
+        Statement s4 = createStatement();
         updateCount = s4.executeUpdate("delete from t1 where current of " +
                                        rs.getCursorName());
         
@@ -575,6 +593,9 @@
         assertEquals("Expected update count to be 0", 0, updateCount);
         
         rs.close();
+        s.close();
+        s3.close();
+        s4.close();
     }
     
     /**
@@ -584,7 +605,7 @@
     public void testIndexedUpdateCursor1()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1 where a=1");
@@ -592,6 +613,7 @@
         assertTrue("Expected to get a tuple on rs.next()", rs.next());
         verifyTuple(rs);
         updateTuple(rs);
+        s.close();
         
     }
     
@@ -602,7 +624,7 @@
     public void testIndexedUpdateCursor2()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY,
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs =
@@ -611,6 +633,7 @@
         assertTrue("Expected to get a tuple on rs.next()", rs.next());
         verifyTuple(rs);
         updateTuple(rs);
+        s.close();
     }
     
     /**
@@ -622,7 +645,7 @@
      * to insert a row without being on insert row.
      */
     public void testInsertRowWithScrollCursor() throws SQLException {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                                           ResultSet.CONCUR_UPDATABLE);
         
         int currentPosition, lastRow;
@@ -773,7 +796,7 @@
         testIndexedScrollInsensitiveUpdateCursorWithoutForUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
@@ -785,6 +808,7 @@
         rs.previous();
         verifyTuple(rs);
         updateTuple(rs);
+        s.close();
     }
     
     /**
@@ -795,7 +819,7 @@
         testIndexedScrollInsensitiveUpdateCursorWithForUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
@@ -818,7 +842,7 @@
     public void testPrimaryKeyUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
@@ -835,7 +859,7 @@
                 rs.updateRow();
             }
         }
-        PreparedStatement ps = con.prepareStatement
+        PreparedStatement ps = prepareStatement
             ("select * from t1 where id=?");
         for (int i=0; i<recordCount; i++) {
             int key = (i%2==0) ? -i : i;
@@ -850,6 +874,8 @@
                        "however rs2.next returned another row",
                        !rs2.next());
         }
+        s.close();
+        ps.close();
     }
         
     /**
@@ -859,7 +885,7 @@
     public void testOtherPrimaryKeyUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
@@ -867,7 +893,7 @@
         
         rs.last();
         int primaryKey = rs.getInt(1);
-        PreparedStatement ps = con.prepareStatement
+        PreparedStatement ps = prepareStatement
             ("update t1 set id = ? where id= ?");
         ps.setInt(1, -primaryKey);
         ps.setInt(2, primaryKey);
@@ -878,7 +904,7 @@
         rs.updateInt(3, -777);
         rs.updateRow();
         
-        PreparedStatement ps2 = con.prepareStatement
+        PreparedStatement ps2 = prepareStatement
             ("select * from t1 where id=?");
         ps2.setInt(1, -primaryKey);
         ResultSet rs2 = ps2.executeQuery();
@@ -890,6 +916,11 @@
         assertEquals("Expected b=-777", -777, rs2.getInt(3));
         assertTrue("Did not expect more than 1 row, however " +
                    "rs2.next() returned another row", !rs2.next());
+        
+        
+        s.close();
+        ps.close();
+        ps2.close();
     }
     
     /**
@@ -900,7 +931,7 @@
     public void testOtherAndOwnPrimaryKeyUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
@@ -908,7 +939,7 @@
         
         rs.last();
         int primaryKey = rs.getInt(1);
-        PreparedStatement ps = con.prepareStatement
+        PreparedStatement ps = prepareStatement
             ("update t1 set id = ? where id= ?");
         ps.setInt(1, -primaryKey);
         ps.setInt(2, primaryKey);
@@ -920,7 +951,7 @@
         rs.updateRow();
         
         PreparedStatement ps2 =
-            con.prepareStatement("select * from t1 where id=?");
+            prepareStatement("select * from t1 where id=?");
         ps2.setInt(1, primaryKey*10);
         ResultSet rs2 = ps2.executeQuery();
         assertTrue("Expected query to have 1 row", rs2.next());
@@ -931,6 +962,10 @@
         assertEquals("Expected b=-777", -777, rs2.getInt(3));
         assertTrue("Did not expect more than 1 row, however " +
                    "rs2.next() returned another row", !rs2.next());
+        
+        s.close();
+        ps.close();
+        ps2.close();
     }
     
     /**
@@ -939,7 +974,7 @@
     public void testMultipleKeyUpdates()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
@@ -947,7 +982,7 @@
         
         rs.last();
         int primaryKey = rs.getInt(1);
-        PreparedStatement ps = con.prepareStatement
+        PreparedStatement ps = s.getConnection().prepareStatement
             ("update t1 set id = ? where id= ?");
         ps.setInt(1, -primaryKey);
         ps.setInt(2, primaryKey);
@@ -969,6 +1004,8 @@
             rs.updateInt(3, (-777 -i));
             rs.updateRow();
         }
+        rs.close();
+        s.close();
     }
     
     /**
@@ -978,7 +1015,7 @@
         throws SQLException 
     {
         
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
@@ -992,7 +1029,7 @@
             rs.updateInt(2, newKey--);
             rs.updateRow();
         }
-        PreparedStatement ps = con.prepareStatement
+        PreparedStatement ps = prepareStatement
             ("select * from t1 where a=?");
         for (int i=0; i<recordCount; i++) {
             int key = -i;
@@ -1007,6 +1044,9 @@
                        "however rs2.next returned another row",
                        !rs2.next());
         }
+        
+        s.close();
+        ps.close();
     }
     
     /**
@@ -1016,7 +1056,7 @@
     public void testOtherSecondaryKeyUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
@@ -1025,7 +1065,7 @@
         rs.last();
         int indexedKey = rs.getInt(2);
         PreparedStatement ps =
-            con.prepareStatement("update t1 set a = ? where a= ?");
+            prepareStatement("update t1 set a = ? where a= ?");
         ps.setInt(1, -indexedKey);
         ps.setInt(2, indexedKey);
         assertEquals("Expected one row to be updated", 1,
@@ -1036,7 +1076,7 @@
         rs.updateRow();
         
         PreparedStatement ps2 =
-            con.prepareStatement("select * from t1 where a=?");
+            prepareStatement("select * from t1 where a=?");
         ps2.setInt(1, -indexedKey);
         ResultSet rs2 = ps2.executeQuery();
         assertTrue("Expected query to have 1 row", rs2.next());
@@ -1047,6 +1087,10 @@
         assertEquals("Expected b=-777", -777, rs2.getInt(3));
         assertTrue("Did not expect more than 1 row, however " +
                    "rs2.next() returned another row", !rs2.next());
+        
+        s.close();
+        ps.close();
+        ps2.close();
     }
     
     /**
@@ -1055,7 +1099,7 @@
     public void testScrollInsensitiveReadOnly1()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_READ_ONLY);
         s.setCursorName(getNextCursorName());
@@ -1064,6 +1108,7 @@
         scrollForward(rs);
         scrollBackward(rs);
         rs.close();
+        s.close();
     }
     
     /**
@@ -1072,13 +1117,14 @@
     public void testForwardOnlyConcurUpdatableWithForUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1 for update");
         
         scrollForwardAndUpdate(rs);
         rs.close();
+        s.close();
     }
     
     /**
@@ -1087,13 +1133,14 @@
     public void testForwardOnlyConcurUpdatableWithoutForUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1");
         
         scrollForwardAndUpdate(rs);
         rs.close();
+        s.close();
     }
     
     /**
@@ -1103,13 +1150,14 @@
     public void testPositionedUpdateWithoutForUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
         s.setCursorName("MYCURSOR");
         ResultSet rs = s.executeQuery("select * from t1");
         
         scrollForwardAndUpdatePositioned(rs);
         rs.close();
+        s.close();
     }
     
     /**
@@ -1119,12 +1167,13 @@
     public void testPositionedUpdateWithForUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement();
+        Statement s = createStatement();
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1 for update");
         
         scrollForwardAndUpdatePositioned(rs);
         rs.close();
+        s.close();
     }
     
     /**
@@ -1133,7 +1182,7 @@
     public void testScrollablePositionedUpdateWithForUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement
+        Statement s = createStatement
             (ResultSet.TYPE_SCROLL_INSENSITIVE,
              ResultSet.CONCUR_READ_ONLY);
         s.setCursorName("MYCURSOR");
@@ -1152,7 +1201,7 @@
         final int previousA = rs.getInt(2);
         final int previousB = rs.getInt(3);
         println(rs.getCursorName());
-        PreparedStatement ps = con.prepareStatement
+        PreparedStatement ps = prepareStatement
             ("update T1 set a=?,b=? where current of " + rs.getCursorName());
         ps.setInt(1, 666);
         ps.setInt(2, 777);
@@ -1181,7 +1230,9 @@
                         "," + rs.getInt(3) + "," + rs.getString(4)+ ")");
             }
         }
-        
+
+        s.close();
+        ps.close();
     }
     
     /**
@@ -1191,12 +1242,13 @@
     public void testScrollInsensitiveConcurUpdatableWithForUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1 for update");
         scrollForwardAndUpdate(rs);
         rs.close();
+        s.close();
     }
     
     /**
@@ -1206,7 +1258,7 @@
     public void testScrollInsensitiveConcurUpdatableWithForUpdate2()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         assertEquals("Invalid resultset concurrency on statement", 
                      ResultSet.CONCUR_UPDATABLE, s.getResultSetConcurrency());
@@ -1218,6 +1270,7 @@
         scrollForward(rs);
         scrollBackwardAndUpdate(rs);
         rs.close();
+        s.close();
     }
     
     /**
@@ -1256,7 +1309,7 @@
             assertEquals("Incorrect row updated for row " + count, 1000, a);
         }
         rs.close();
-        Statement s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        Statement s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                           ResultSet.CONCUR_READ_ONLY);
         s.setCursorName(getNextCursorName());
         rs = s.executeQuery("select * from t1");
@@ -1267,6 +1320,7 @@
             int b = rs.getInt(3);
             println("Updated tuple:" + id + "," + a + "," + b);
         }
+        s.close();
     }
     
     /**
@@ -1277,12 +1331,13 @@
     public void testScrollInsensitiveConcurUpdatableWithForUpdate3()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select a,b from t1 for update");
         
         testScrollInsensistiveConurUpdatable3(rs);
+        s.close();
     }
     
     /**
@@ -1292,13 +1347,14 @@
     public void testScrollInsensitiveConcurUpdatableWithoutForUpdate1()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1");
         
         scrollForwardAndUpdate(rs);
         rs.close();
+        s.close();
     }
     
     /**
@@ -1308,7 +1364,7 @@
     public void testScrollInsensitiveConcurUpdatableWithoutForUpdate2()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select * from t1");
@@ -1316,6 +1372,7 @@
         scrollForward(rs);
         scrollBackwardAndUpdate(rs);
         rs.close();
+        s.close();
     }
     
     /**
@@ -1326,12 +1383,13 @@
     public void testScrollInsensitiveConcurUpdatableWithoutForUpdate3()
         throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select a,b from t1");
         
         testScrollInsensistiveConurUpdatable3(rs);
+        s.close();
     }
     
     /**
@@ -1383,7 +1441,7 @@
      * and deleteRow() methods.
      */
     public void testRowUpdatedAndRowDeleted() throws SQLException {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                            ResultSet.CONCUR_UPDATABLE);
         s.setCursorName(getNextCursorName());
         ResultSet rs = s.executeQuery("select a,b from t1");
@@ -1414,7 +1472,7 @@
      */
     public void testDetectabilityExceptions() throws SQLException 
     {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1");
         
@@ -1447,7 +1505,7 @@
         s.close();
 
         // Not strictly SUR, but fixed in same patch, so we test it here.
-        s = con.createStatement(ResultSet.TYPE_FORWARD_ONLY, 
+        s = createStatement(ResultSet.TYPE_FORWARD_ONLY, 
                                 ResultSet.CONCUR_UPDATABLE);
         rs = s.executeQuery("select * from t1");
 
@@ -1486,7 +1544,7 @@
      *
      */
     public void testDowngradeToScrollReadOnly() throws SQLException {
-        Statement s = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
+        Statement s = createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, 
                                           ResultSet.CONCUR_UPDATABLE);
         ResultSet rs = s.executeQuery("select * from t1 order by b");