You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by th...@apache.org on 2023/02/14 03:38:48 UTC

[commons-dbutils] branch master updated (5d0b1e3 -> bd8ebef)

This is an automated email from the ASF dual-hosted git repository.

thecarlhall pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbutils.git


    from 5d0b1e3  Bump actions/setup-java from 3.9.0 to 3.10.0 (#179)
     new 654c4a6  Fetch parameter metadata only once. Apply patch PR-78 from github.com/frank-king
     new de4a122  Promote optimization as default for fetching the parameter metadata only once Clean up duplicated tests
     new bd8ebef  Merge branch 'frank-king-prefetch_pmd'

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../commons/dbutils/AbstractQueryRunner.java       | 67 +++++++++++++++++-----
 .../org/apache/commons/dbutils/QueryRunner.java    |  7 ++-
 .../apache/commons/dbutils/QueryRunnerTest.java    | 26 +++++++--
 3 files changed, 81 insertions(+), 19 deletions(-)


[commons-dbutils] 01/03: Fetch parameter metadata only once. Apply patch PR-78 from github.com/frank-king

Posted by th...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

thecarlhall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbutils.git

commit 654c4a6f813acd9850eecb073bef1431da35fe90
Author: Frank King <fr...@gmail.com>
AuthorDate: Mon Jan 16 21:06:21 2023 -0500

    Fetch parameter metadata only once. Apply patch PR-78 from github.com/frank-king
---
 .../commons/dbutils/AbstractQueryRunner.java       |  48 ++++++-
 .../org/apache/commons/dbutils/QueryRunner.java    |   7 +-
 .../apache/commons/dbutils/QueryRunnerTest.java    | 141 +++++++++++++++++++++
 3 files changed, 192 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java b/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
index c6492c9..f740823 100644
--- a/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
+++ b/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
@@ -258,6 +258,28 @@ public abstract class AbstractQueryRunner {
         }
     }
 
+    /**
+     * Get the {@code ParameterMetaData} of the prepared statement, if the {@code pmdKnownBroken}
+     * is set to false.
+     *
+     * @param stmt
+     *            PreparedStatement of which to query the metadata of parameters
+     * @return the metadata of parameters
+     * @throws SQLException
+     *            if a database access error occurs
+     */
+    public ParameterMetaData getParameterMetaData(final PreparedStatement stmt) throws SQLException {
+        ParameterMetaData pmd = null;
+        if (!pmdKnownBroken) {
+            try {
+                pmd = stmt.getParameterMetaData();
+            } catch (final SQLFeatureNotSupportedException ex) {
+                pmdKnownBroken = true;
+            }
+        }
+        return pmd;
+    }
+
     /**
      * Fill the {@code PreparedStatement} replacement parameters with the
      * given objects.
@@ -270,14 +292,34 @@ public abstract class AbstractQueryRunner {
      * @throws SQLException
      *             if a database access error occurs
      */
-    public void fillStatement(final PreparedStatement stmt, final Object... params)
+    public void fillStatement(final PreparedStatement stmt, final Object... params) throws SQLException {
+        ParameterMetaData pmd = null;
+        if (!pmdKnownBroken) {
+            pmd = this.getParameterMetaData(stmt);
+        }
+        fillStatement(stmt, pmd, params);
+    }
+
+    /**
+     * Fill the {@code PreparedStatement} replacement parameters with the
+     * given objects, and prefetched parameter metadata.
+     *
+     * @param stmt
+     *            PreparedStatement to fill
+     * @param pmd
+     *            Prefetched parameter metadata
+     * @param params
+     *            Query replacement parameters; {@code null} is a valid
+     *            value to pass in.
+     * @throws SQLException
+     *             if a database access error occurs
+     */
+    public void fillStatement(final PreparedStatement stmt, final ParameterMetaData pmd, final Object... params)
             throws SQLException {
 
         // check the parameter count, if we can
-        ParameterMetaData pmd = null;
         if (!pmdKnownBroken) {
             try {
-                pmd = stmt.getParameterMetaData();
                 if (pmd == null) { // can be returned by implementations that don't support the method
                     pmdKnownBroken = true;
                 } else {
diff --git a/src/main/java/org/apache/commons/dbutils/QueryRunner.java b/src/main/java/org/apache/commons/dbutils/QueryRunner.java
index a55e7d0..cba4dfd 100644
--- a/src/main/java/org/apache/commons/dbutils/QueryRunner.java
+++ b/src/main/java/org/apache/commons/dbutils/QueryRunner.java
@@ -18,6 +18,7 @@ package org.apache.commons.dbutils;
 
 import java.sql.CallableStatement;
 import java.sql.Connection;
+import java.sql.ParameterMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
@@ -180,12 +181,16 @@ public class QueryRunner extends AbstractQueryRunner {
         }
 
         PreparedStatement stmt = null;
+        ParameterMetaData pmd = null;
         int[] rows = null;
         try {
             stmt = this.prepareStatement(conn, sql);
+            // When the batch size is large, prefetching parameter metadata before filling
+            // the statement can reduce lots of JDBC communications.
+            pmd = this.getParameterMetaData(stmt);
 
             for (final Object[] param : params) {
-                this.fillStatement(stmt, param);
+                this.fillStatement(stmt, pmd, param);
                 stmt.addBatch();
             }
             rows = stmt.executeBatch();
diff --git a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
index e1746c9..bfc33ae 100644
--- a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
@@ -103,6 +103,17 @@ public class QueryRunnerTest {
         verify(conn, times(0)).close();    // make sure we do not close the connection, since QueryRunner.batch(Connection, String, Object[][]) does not close connections
     }
 
+    private void callGoodBatchPrefetchPmdTrue(final Connection conn, final Object[][] params) throws Exception {
+        when(meta.getParameterCount()).thenReturn(2);
+        runner.batch(conn, "select * from blah where ? = ?", true, params);
+
+        verify(prepStmt, times(1)).getParameterMetaData();
+        verify(prepStmt, times(2)).addBatch();
+        verify(prepStmt, times(1)).executeBatch();
+        verify(prepStmt, times(1)).close();    // make sure we closed the statement
+        verify(conn, times(0)).close();    // make sure we do not close the connection, since QueryRunner.batch(Connection, String, Object[][]) does not close connections
+    }
+
     private void callGoodBatch(final Object[][] params) throws Exception {
         when(meta.getParameterCount()).thenReturn(2);
         runner.batch("select * from blah where ? = ?", params);
@@ -113,6 +124,18 @@ public class QueryRunnerTest {
         verify(conn, times(1)).close();    // make sure we closed the connection
     }
 
+    private void callGoodBatchPrefetchPmdTrue(final Object[][] params, boolean pmdCheck) throws Exception {
+        when(meta.getParameterCount()).thenReturn(2);
+        runner.batch("select * from blah where ? = ?", true, params);
+
+        verify(prepStmt, times(pmdCheck ? 1 : 0)).getParameterMetaData();
+        verify(prepStmt, times(2)).addBatch();
+        verify(prepStmt, times(1)).executeBatch();
+        verify(prepStmt, times(1)).close();    // make sure we closed the statement
+        verify(conn, times(1)).close();    // make sure we closed the connection
+    }
+
+
     @Test
     public void testGoodBatch() throws Exception {
         final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
@@ -120,6 +143,13 @@ public class QueryRunnerTest {
         callGoodBatch(params);
     }
 
+    @Test
+    public void testGoodBatchPrefetchPmdTrue() throws Exception {
+        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+        callGoodBatchPrefetchPmdTrue(params, true);
+    }
+
     @Test
     public void testGoodBatchPmdTrue() throws Exception {
         runner = new QueryRunner(dataSource, true);
@@ -128,6 +158,15 @@ public class QueryRunnerTest {
         callGoodBatch(params);
     }
 
+    @Test
+    public void testGoodBatchPmdTrueAndPrefetchPmdTrue() throws Exception {
+        runner = new QueryRunner(dataSource, true);
+        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+        callGoodBatchPrefetchPmdTrue(params, false);
+    }
+
+
     @Test
     public void testGoodBatchDefaultConstructor() throws Exception {
         runner = new QueryRunner();
@@ -136,6 +175,15 @@ public class QueryRunnerTest {
         callGoodBatch(conn, params);
     }
 
+    @Test
+    public void testGoodBatchDefaultConstructorPrefetchPmdTrue() throws Exception {
+        runner = new QueryRunner();
+        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+        callGoodBatchPrefetchPmdTrue(conn, params);
+    }
+
+
     @Test
     public void testNullParamsBatch() throws Exception {
         final String[][] params = new String[][] { { null, "unit" }, { "test", null } };
@@ -143,6 +191,13 @@ public class QueryRunnerTest {
         callGoodBatch(params);
     }
 
+    @Test
+    public void testNullParamsBatchPrefetchPmdTrue() throws Exception {
+        final String[][] params = new String[][] { { null, "unit" }, { "test", null } };
+
+        callGoodBatchPrefetchPmdTrue(params, true);
+    }
+
 
 
     // helper method for calling batch when an exception is expected
@@ -165,6 +220,28 @@ public class QueryRunnerTest {
         }
     }
 
+    // helper method for calling batch when an exception is expected
+    private void callBatchWithExceptionPrefetchPmd(final String sql, final Object[][] params) throws Exception {
+        boolean caught = false;
+
+        try {
+            runner.batch(sql, params);
+
+            verify(prepStmt, times(1)).getParameterMetaData();
+            verify(prepStmt, times(2)).addBatch();
+            verify(prepStmt, times(1)).executeBatch();
+            verify(prepStmt, times(1)).close();    // make sure the statement is closed
+            verify(conn, times(1)).close();    // make sure the connection is closed
+        } catch(final SQLException e) {
+            caught = true;
+        }
+
+        if(!caught) {
+            fail("Exception never thrown, but expected");
+        }
+    }
+
+
     @Test
     public void testTooFewParamsBatch() throws Exception {
         final String[][] params = new String[][] { { "unit" }, { "test" } };
@@ -179,6 +256,21 @@ public class QueryRunnerTest {
         callBatchWithException("select * from blah where ? = ?", params);
     }
 
+    @Test
+    public void testTooFewParamsBatchPrefetchPmd() throws Exception {
+        final String[][] params = new String[][] { { "unit" }, { "test" } };
+
+        callBatchWithExceptionPrefetchPmd("select * from blah where ? = ?", params);
+    }
+
+    @Test
+    public void testTooManyParamsBatchPrefetchPmd() throws Exception {
+        final String[][] params = new String[][] { { "unit", "unit", "unit" }, { "test", "test", "test" } };
+
+        callBatchWithExceptionPrefetchPmd("select * from blah where ? = ?", params);
+    }
+
+
     @Test(expected=SQLException.class)
     public void testNullConnectionBatch() throws Exception {
         final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
@@ -188,6 +280,17 @@ public class QueryRunnerTest {
         runner.batch("select * from blah where ? = ?", params);
     }
 
+    @Test(expected=SQLException.class)
+    public void testNullConnectionBatchPrefetchPmd() throws Exception {
+        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+        when(meta.getParameterCount()).thenReturn(2);
+        when(dataSource.getConnection()).thenReturn(null);
+
+        runner.batch("select * from blah where ? = ?", true, params);
+    }
+
+
     @Test(expected=SQLException.class)
     public void testNullSqlBatch() throws Exception {
         final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
@@ -195,11 +298,29 @@ public class QueryRunnerTest {
         runner.batch(null, params);
     }
 
+    @Test(expected=SQLException.class)
+    public void testNullSqlBatchPrefetchPmd() throws Exception {
+        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+        when(meta.getParameterCount()).thenReturn(2);
+
+        runner.batch(null, true, params);
+    }
+
+
     @Test(expected=SQLException.class)
     public void testNullParamsArgBatch() throws Exception {
         runner.batch("select * from blah where ? = ?", null);
     }
 
+    @Test(expected=SQLException.class)
+    public void testNullParamsArgBatchPrefetchPmd() throws Exception {
+        when(meta.getParameterCount()).thenReturn(2);
+
+        runner.batch("select * from blah where ? = ?", true, null);
+    }
+
+
     @Test
     public void testAddBatchException() throws Exception {
         final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
@@ -207,6 +328,16 @@ public class QueryRunnerTest {
         callBatchWithException("select * from blah where ? = ?", params);
     }
 
+    @Test
+    public void testAddBatchExceptionPrefetchPmd() throws Exception {
+        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+        doThrow(new SQLException()).when(prepStmt).addBatch();
+
+        callBatchWithExceptionPrefetchPmd("select * from blah where ? = ?", params);
+    }
+
+
     @Test
     public void testExecuteBatchException() throws Exception {
         final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
@@ -214,6 +345,16 @@ public class QueryRunnerTest {
         callBatchWithException("select * from blah where ? = ?", params);
     }
 
+    @Test
+    public void testExecuteBatchExceptionPrefetchPmd() throws Exception {
+        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
+
+        doThrow(new SQLException()).when(prepStmt).executeBatch();
+
+        callBatchWithExceptionPrefetchPmd("select * from blah where ? = ?", params);
+    }
+
+
 
     //
     // Query test cases


[commons-dbutils] 03/03: Merge branch 'frank-king-prefetch_pmd'

Posted by th...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

thecarlhall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbutils.git

commit bd8ebef1303545470c55ad814313164f84e7e6e2
Merge: 5d0b1e3 de4a122
Author: Carl Hall <th...@apache.org>
AuthorDate: Mon Feb 13 22:37:04 2023 -0500

    Merge branch 'frank-king-prefetch_pmd'

 .../commons/dbutils/AbstractQueryRunner.java       | 67 +++++++++++++++++-----
 .../org/apache/commons/dbutils/QueryRunner.java    |  7 ++-
 .../apache/commons/dbutils/QueryRunnerTest.java    | 26 +++++++--
 3 files changed, 81 insertions(+), 19 deletions(-)


[commons-dbutils] 02/03: Promote optimization as default for fetching the parameter metadata only once Clean up duplicated tests

Posted by th...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

thecarlhall pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbutils.git

commit de4a1224dbfae557abdf3e237ee29df43e8d145b
Author: Carl Hall <th...@apache.org>
AuthorDate: Mon Feb 13 22:30:40 2023 -0500

    Promote optimization as default for fetching the parameter metadata only once
    Clean up duplicated tests
---
 .../commons/dbutils/AbstractQueryRunner.java       |  31 +++--
 .../apache/commons/dbutils/QueryRunnerTest.java    | 145 ++-------------------
 2 files changed, 25 insertions(+), 151 deletions(-)

diff --git a/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java b/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
index f740823..fd433e3 100644
--- a/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
+++ b/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
@@ -295,7 +295,15 @@ public abstract class AbstractQueryRunner {
     public void fillStatement(final PreparedStatement stmt, final Object... params) throws SQLException {
         ParameterMetaData pmd = null;
         if (!pmdKnownBroken) {
-            pmd = this.getParameterMetaData(stmt);
+            try {
+                pmd = this.getParameterMetaData(stmt);
+                if (pmd == null) { // can be returned by implementations that don't support the method
+                    pmdKnownBroken = true;
+                }
+            } catch (final SQLFeatureNotSupportedException ex) {
+                pmdKnownBroken = true;
+            }
+            // TODO see DBUTILS-117: would it make sense to catch any other SQLEx types here?
         }
         fillStatement(stmt, pmd, params);
     }
@@ -318,23 +326,14 @@ public abstract class AbstractQueryRunner {
             throws SQLException {
 
         // check the parameter count, if we can
-        if (!pmdKnownBroken) {
-            try {
-                if (pmd == null) { // can be returned by implementations that don't support the method
-                    pmdKnownBroken = true;
-                } else {
-                    final int stmtCount = pmd.getParameterCount();
-                    final int paramsCount = params == null ? 0 : params.length;
+        if (!pmdKnownBroken && pmd != null) {
+            final int stmtCount = pmd.getParameterCount();
+            final int paramsCount = params == null ? 0 : params.length;
 
-                    if (stmtCount != paramsCount) {
-                        throw new SQLException("Wrong number of parameters: expected "
-                                + stmtCount + ", was given " + paramsCount);
-                    }
-                }
-            } catch (final SQLFeatureNotSupportedException ex) {
-                pmdKnownBroken = true;
+            if (stmtCount != paramsCount) {
+                throw new SQLException("Wrong number of parameters: expected "
+                        + stmtCount + ", was given " + paramsCount);
             }
-            // TODO see DBUTILS-117: would it make sense to catch any other SQLEx types here?
         }
 
         // nothing to do here
diff --git a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
index bfc33ae..d408398 100644
--- a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
+++ b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java
@@ -47,7 +47,6 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.junit.MockitoJUnitRunner;
 import org.mockito.stubbing.Answer;
@@ -97,16 +96,6 @@ public class QueryRunnerTest {
         when(meta.getParameterCount()).thenReturn(2);
         runner.batch(conn, "select * from blah where ? = ?", params);
 
-        verify(prepStmt, times(2)).addBatch();
-        verify(prepStmt, times(1)).executeBatch();
-        verify(prepStmt, times(1)).close();    // make sure we closed the statement
-        verify(conn, times(0)).close();    // make sure we do not close the connection, since QueryRunner.batch(Connection, String, Object[][]) does not close connections
-    }
-
-    private void callGoodBatchPrefetchPmdTrue(final Connection conn, final Object[][] params) throws Exception {
-        when(meta.getParameterCount()).thenReturn(2);
-        runner.batch(conn, "select * from blah where ? = ?", true, params);
-
         verify(prepStmt, times(1)).getParameterMetaData();
         verify(prepStmt, times(2)).addBatch();
         verify(prepStmt, times(1)).executeBatch();
@@ -115,18 +104,12 @@ public class QueryRunnerTest {
     }
 
     private void callGoodBatch(final Object[][] params) throws Exception {
-        when(meta.getParameterCount()).thenReturn(2);
-        runner.batch("select * from blah where ? = ?", params);
-
-        verify(prepStmt, times(2)).addBatch();
-        verify(prepStmt, times(1)).executeBatch();
-        verify(prepStmt, times(1)).close();    // make sure we closed the statement
-        verify(conn, times(1)).close();    // make sure we closed the connection
+        callGoodBatch(params, true);
     }
 
-    private void callGoodBatchPrefetchPmdTrue(final Object[][] params, boolean pmdCheck) throws Exception {
+    private void callGoodBatch(final Object[][] params, boolean pmdCheck) throws Exception {
         when(meta.getParameterCount()).thenReturn(2);
-        runner.batch("select * from blah where ? = ?", true, params);
+        runner.batch("select * from blah where ? = ?", params);
 
         verify(prepStmt, times(pmdCheck ? 1 : 0)).getParameterMetaData();
         verify(prepStmt, times(2)).addBatch();
@@ -143,30 +126,14 @@ public class QueryRunnerTest {
         callGoodBatch(params);
     }
 
-    @Test
-    public void testGoodBatchPrefetchPmdTrue() throws Exception {
-        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
-        callGoodBatchPrefetchPmdTrue(params, true);
-    }
-
     @Test
     public void testGoodBatchPmdTrue() throws Exception {
         runner = new QueryRunner(dataSource, true);
         final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
 
-        callGoodBatch(params);
-    }
-
-    @Test
-    public void testGoodBatchPmdTrueAndPrefetchPmdTrue() throws Exception {
-        runner = new QueryRunner(dataSource, true);
-        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
-        callGoodBatchPrefetchPmdTrue(params, false);
+        callGoodBatch(params, false);
     }
 
-
     @Test
     public void testGoodBatchDefaultConstructor() throws Exception {
         runner = new QueryRunner();
@@ -175,15 +142,6 @@ public class QueryRunnerTest {
         callGoodBatch(conn, params);
     }
 
-    @Test
-    public void testGoodBatchDefaultConstructorPrefetchPmdTrue() throws Exception {
-        runner = new QueryRunner();
-        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
-        callGoodBatchPrefetchPmdTrue(conn, params);
-    }
-
-
     @Test
     public void testNullParamsBatch() throws Exception {
         final String[][] params = new String[][] { { null, "unit" }, { "test", null } };
@@ -191,37 +149,10 @@ public class QueryRunnerTest {
         callGoodBatch(params);
     }
 
-    @Test
-    public void testNullParamsBatchPrefetchPmdTrue() throws Exception {
-        final String[][] params = new String[][] { { null, "unit" }, { "test", null } };
-
-        callGoodBatchPrefetchPmdTrue(params, true);
-    }
-
-
 
     // helper method for calling batch when an exception is expected
     private void callBatchWithException(final String sql, final Object[][] params) throws Exception {
-        boolean caught = false;
-
-        try {
-            runner.batch(sql, params);
-
-            verify(prepStmt, times(2)).addBatch();
-            verify(prepStmt, times(1)).executeBatch();
-            verify(prepStmt, times(1)).close();    // make sure the statement is closed
-            verify(conn, times(1)).close();    // make sure the connection is closed
-        } catch(final SQLException e) {
-            caught = true;
-        }
-
-        if(!caught) {
-            fail("Exception never thrown, but expected");
-        }
-    }
-
-    // helper method for calling batch when an exception is expected
-    private void callBatchWithExceptionPrefetchPmd(final String sql, final Object[][] params) throws Exception {
+        when(meta.getParameterCount()).thenReturn(2);
         boolean caught = false;
 
         try {
@@ -233,6 +164,8 @@ public class QueryRunnerTest {
             verify(prepStmt, times(1)).close();    // make sure the statement is closed
             verify(conn, times(1)).close();    // make sure the connection is closed
         } catch(final SQLException e) {
+            System.out.println("[TEST] The following exception is expected:");
+            System.out.println(e);
             caught = true;
         }
 
@@ -241,7 +174,6 @@ public class QueryRunnerTest {
         }
     }
 
-
     @Test
     public void testTooFewParamsBatch() throws Exception {
         final String[][] params = new String[][] { { "unit" }, { "test" } };
@@ -256,21 +188,6 @@ public class QueryRunnerTest {
         callBatchWithException("select * from blah where ? = ?", params);
     }
 
-    @Test
-    public void testTooFewParamsBatchPrefetchPmd() throws Exception {
-        final String[][] params = new String[][] { { "unit" }, { "test" } };
-
-        callBatchWithExceptionPrefetchPmd("select * from blah where ? = ?", params);
-    }
-
-    @Test
-    public void testTooManyParamsBatchPrefetchPmd() throws Exception {
-        final String[][] params = new String[][] { { "unit", "unit", "unit" }, { "test", "test", "test" } };
-
-        callBatchWithExceptionPrefetchPmd("select * from blah where ? = ?", params);
-    }
-
-
     @Test(expected=SQLException.class)
     public void testNullConnectionBatch() throws Exception {
         final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
@@ -280,16 +197,6 @@ public class QueryRunnerTest {
         runner.batch("select * from blah where ? = ?", params);
     }
 
-    @Test(expected=SQLException.class)
-    public void testNullConnectionBatchPrefetchPmd() throws Exception {
-        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
-        when(meta.getParameterCount()).thenReturn(2);
-        when(dataSource.getConnection()).thenReturn(null);
-
-        runner.batch("select * from blah where ? = ?", true, params);
-    }
-
 
     @Test(expected=SQLException.class)
     public void testNullSqlBatch() throws Exception {
@@ -298,60 +205,28 @@ public class QueryRunnerTest {
         runner.batch(null, params);
     }
 
-    @Test(expected=SQLException.class)
-    public void testNullSqlBatchPrefetchPmd() throws Exception {
-        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
-        when(meta.getParameterCount()).thenReturn(2);
-
-        runner.batch(null, true, params);
-    }
-
 
     @Test(expected=SQLException.class)
     public void testNullParamsArgBatch() throws Exception {
         runner.batch("select * from blah where ? = ?", null);
     }
 
-    @Test(expected=SQLException.class)
-    public void testNullParamsArgBatchPrefetchPmd() throws Exception {
-        when(meta.getParameterCount()).thenReturn(2);
-
-        runner.batch("select * from blah where ? = ?", true, null);
-    }
-
-
     @Test
-    public void testAddBatchException() throws Exception {
-        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
-        callBatchWithException("select * from blah where ? = ?", params);
-    }
-
-    @Test
-    public void testAddBatchExceptionPrefetchPmd() throws Exception {
+    public void testAddBatchExceptionOnAdd() throws Exception {
         final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
 
         doThrow(new SQLException()).when(prepStmt).addBatch();
 
-        callBatchWithExceptionPrefetchPmd("select * from blah where ? = ?", params);
-    }
-
-
-    @Test
-    public void testExecuteBatchException() throws Exception {
-        final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
-
         callBatchWithException("select * from blah where ? = ?", params);
     }
 
     @Test
-    public void testExecuteBatchExceptionPrefetchPmd() throws Exception {
+    public void testExecuteBatchExceptionOnExec() throws Exception {
         final String[][] params = new String[][] { { "unit", "unit" }, { "test", "test" } };
 
         doThrow(new SQLException()).when(prepStmt).executeBatch();
 
-        callBatchWithExceptionPrefetchPmd("select * from blah where ? = ?", params);
+        callBatchWithException("select * from blah where ? = ?", params);
     }