Commons DbUtils
  1. Commons DbUtils
  2. DBUTILS-44

QueryRunner#fillStatement setNull all database fix proposal

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.1
    • Fix Version/s: None
    • Labels:
      None

      Description

      There is currently many open issues ( DBUTILS-14, DBUTILS-31, DBUTILS-39 and DBUTILS-41) concerning the problem with setNull(i+1, Types.VARCHAR) in the QueryRunner#fillStatement method when the given object is null.

      I use Commons DbUtils in several projects, and I have found a workaround which works for any database:
      The problem is that when the object is null, the API does not know to which SQL TYPE it should map the object to.

      I've added an Interface, named SQLParam, which exactely resolve this problem:

      public interface SQLParam {
          /**
           * Returns the object
           * 
           * @return the object
           */
          public Object getObject();
      
          /**
           * Returns the SQL type of the object,
           * must be one of {@link java.sql.Types}
           * 
           * @return the type of the object
           * @see java.sql.Types
           */
          public int getType();
      }
      

      Then I've changed the QueryRunner API, by replacing all Object param and Object[] params by SQLParam param and SQLParam[] params (in a new QueryRunnerSQLParam class).

      It does work just well for me; any comments gladly appreciated.

      1. SQLParamImpl.java
        4 kB
        Julien Aymé
      2. SQLParamBuilder.java
        8 kB
        Julien Aymé
      3. SQLParam.java
        0.5 kB
        Julien Aymé
      4. QueryRunnerSQLParam.java
        19 kB
        Julien Aymé

        Activity

        Hide
        Julien Aymé added a comment -

        Attached SQLParam interface, and the modified QueryRunner class (QueryRunnerSQLParam)

        Show
        Julien Aymé added a comment - Attached SQLParam interface, and the modified QueryRunner class (QueryRunnerSQLParam)
        Hide
        Julien Aymé added a comment -

        Attached default implementation of SQLParam (SQLParamImpl), and a facility builder class (similar to Lang builders: SQLParamBuilder)

        Show
        Julien Aymé added a comment - Attached default implementation of SQLParam (SQLParamImpl), and a facility builder class (similar to Lang builders: SQLParamBuilder)
        Hide
        Henri Yandell added a comment -

        svn ci -m "Merging in Dab Fabulich's work on https://svn.apache.org/repos/asf/commons/sandbox/dbutils/bugfixing from -r741987:747723. Resolving DBUTILS-34 - DBUTILS-37 - DBUTILS-29 - DBUTILS-14 - DBUTILS-31 - DBUTILS-39 - DBUTILS-41 - DBUTILS-44 - DBUTILS-33 - DBUTILS-42 - DBUTILS-40"

        Sending pom.xml
        Sending src/java/org/apache/commons/dbutils/BasicRowProcessor.java
        Sending src/java/org/apache/commons/dbutils/BeanProcessor.java
        Sending src/java/org/apache/commons/dbutils/QueryRunner.java
        Adding src/java/org/apache/commons/dbutils/handlers/AbstractListHandler.java
        Sending src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java
        Sending src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java
        Sending src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java
        Deleting src/java/org/apache/commons/dbutils/handlers/GenericListHandler.java
        Sending src/java/org/apache/commons/dbutils/handlers/MapListHandler.java
        Sending src/test/org/apache/commons/dbutils/BaseTestCase.java
        Adding src/test/org/apache/commons/dbutils/QueryRunnerTest.java
        Transmitting file data .........
        Committed revision 747724.

        Show
        Henri Yandell added a comment - svn ci -m "Merging in Dab Fabulich's work on https://svn.apache.org/repos/asf/commons/sandbox/dbutils/bugfixing from -r741987:747723. Resolving DBUTILS-34 - DBUTILS-37 - DBUTILS-29 - DBUTILS-14 - DBUTILS-31 - DBUTILS-39 - DBUTILS-41 - DBUTILS-44 - DBUTILS-33 - DBUTILS-42 - DBUTILS-40 " Sending pom.xml Sending src/java/org/apache/commons/dbutils/BasicRowProcessor.java Sending src/java/org/apache/commons/dbutils/BeanProcessor.java Sending src/java/org/apache/commons/dbutils/QueryRunner.java Adding src/java/org/apache/commons/dbutils/handlers/AbstractListHandler.java Sending src/java/org/apache/commons/dbutils/handlers/ArrayListHandler.java Sending src/java/org/apache/commons/dbutils/handlers/BeanListHandler.java Sending src/java/org/apache/commons/dbutils/handlers/ColumnListHandler.java Deleting src/java/org/apache/commons/dbutils/handlers/GenericListHandler.java Sending src/java/org/apache/commons/dbutils/handlers/MapListHandler.java Sending src/test/org/apache/commons/dbutils/BaseTestCase.java Adding src/test/org/apache/commons/dbutils/QueryRunnerTest.java Transmitting file data ......... Committed revision 747724.
        Hide
        Dan Fabulich added a comment -

        Removing "Fix Version: 1.2" since this is really a dupe; it clutters the release notes.

        Show
        Dan Fabulich added a comment - Removing "Fix Version: 1.2" since this is really a dupe; it clutters the release notes.

          People

          • Assignee:
            Unassigned
            Reporter:
            Julien Aymé
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development