commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thecarlh...@apache.org
Subject [30/50] commons-dbutils git commit: DBUTILS-117 Error handling possible getParameterMetaData() results - handle SQLFeatureNotSupportedException
Date Fri, 07 Jul 2017 02:06:05 GMT
DBUTILS-117 Error handling possible getParameterMetaData() results
- handle SQLFeatureNotSupportedException

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/dbutils/trunk@1645716 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/commons-dbutils/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-dbutils/commit/a36aeedc
Tree: http://git-wip-us.apache.org/repos/asf/commons-dbutils/tree/a36aeedc
Diff: http://git-wip-us.apache.org/repos/asf/commons-dbutils/diff/a36aeedc

Branch: refs/heads/master
Commit: a36aeedc119669fafbc5552107936ef3ee019334
Parents: 2175244
Author: Sebastian Bazley <sebb@apache.org>
Authored: Mon Dec 15 18:38:41 2014 +0000
Committer: Sebastian Bazley <sebb@apache.org>
Committed: Mon Dec 15 18:38:41 2014 +0000

----------------------------------------------------------------------
 src/changes/changes.xml                         |  1 +
 .../commons/dbutils/AbstractQueryRunner.java    | 27 ++++++++++++--------
 2 files changed, 18 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/a36aeedc/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 125956f..7107ebd 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -48,6 +48,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="sebb" type="update" issue="DBUTILS-117" due-to="Vadim Smirnov">
         Error handling possible getParameterMetaData() results
         - allow for null return
+        - handle SQLFeatureNotSupportedException
       </action>
       <action dev="britter" type="update" issue="DBUTILS-119" due-to="Michael Akerman">
         Correct errors in BeanMapHandler JavaDoc

http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/a36aeedc/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java b/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
index dcf2cef..b5ce0cd 100644
--- a/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
+++ b/src/main/java/org/apache/commons/dbutils/AbstractQueryRunner.java
@@ -26,6 +26,7 @@ import java.sql.ParameterMetaData;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
 import java.sql.Statement;
 import java.sql.Types;
 import java.util.Arrays;
@@ -222,18 +223,23 @@ public abstract class AbstractQueryRunner {
         // check the parameter count, if we can
         ParameterMetaData pmd = null;
         if (!pmdKnownBroken) {
-            pmd = stmt.getParameterMetaData();
-            if (pmd == null) { // can be returned by implementations that don't support the
method
-                pmdKnownBroken = true;
-            } else {
-                int stmtCount = pmd.getParameterCount();
-                int paramsCount = params == null ? 0 : params.length;
-    
-                if (stmtCount != paramsCount) {
-                    throw new SQLException("Wrong number of parameters: expected "
-                            + stmtCount + ", was given " + paramsCount);
+            try {
+                pmd = stmt.getParameterMetaData();
+                if (pmd == null) { // can be returned by implementations that don't support
the method
+                    pmdKnownBroken = true;
+                } else {
+                    int stmtCount = pmd.getParameterCount();
+                    int paramsCount = params == null ? 0 : params.length;
+        
+                    if (stmtCount != paramsCount) {
+                        throw new SQLException("Wrong number of parameters: expected "
+                                + stmtCount + ", was given " + paramsCount);
+                    }
                 }
+            } catch (SQLFeatureNotSupportedException ex) {
+                pmdKnownBroken = true;                
             }
+            // TODO see DBUTILS-117: would it make sense to catch any other SQLEx types here?
         }
 
         // nothing to do here
@@ -250,6 +256,7 @@ public abstract class AbstractQueryRunner {
                 // OTHER don't work with Oracle's drivers.
                 int sqlType = Types.VARCHAR;
                 if (!pmdKnownBroken) {
+                    // TODO see DBUTILS-117: does it make sense to catch SQLEx here?
                     try {
                         /*
                          * It's not possible for pmdKnownBroken to change from


Mime
View raw message