You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by "Francis Townsend (JIRA)" <ji...@apache.org> on 2006/06/13 02:46:29 UTC

[jira] Created: (DBUTILS-31) fillStatement setNull bug with the Derby JDBC driver

fillStatement setNull bug with the Derby JDBC driver
----------------------------------------------------

         Key: DBUTILS-31
         URL: http://issues.apache.org/jira/browse/DBUTILS-31
     Project: Commons DbUtils
        Type: Improvement

    Versions: 1.0 Final    
 Environment: Derby 10.1.2.1
    Reporter: Francis Townsend


This has been documented many times before, but I was not happy with the existing code fixes.  The following small code snippet should fix it for all conforming JDBC drivers.

    protected void fillStatement(PreparedStatement stmt, Object[] params)
        throws SQLException {

        if (params == null) {
            return;
        }
        ParameterMetaData pmd = stmt.getParameterMetaData();
        for (int i = 0; i < params.length; i++) {
            if (params[i] != null) {
                stmt.setObject(i + 1, params[i]);
            } else {
                stmt.setNull(i + 1, pmd.getParameterType(i + 1));
            }
        }
    }

The only difference is that you get the parameter meta data and pass that type information to the setNull method.  This should neatly fix this problem, with a very slight additional overhead.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Commented: (DBUTILS-31) fillStatement setNull bug with the Derby JDBC driver

Posted by "Francis Townsend (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DBUTILS-31?page=comments#action_12419585 ] 

Francis Townsend commented on DBUTILS-31:
-----------------------------------------

This code was coded for the JDBC 3.0 specification.  It would need to be modified to run with JDBC 2.1 drivers (check the JDBCMajor version to determine which code to use).  

Also, I have read that the Oracle JDBC driver throws an Exception.  Unfortunately, it does not look as if there is no method that can determine this before calling the getParameterType method.  Which means we would need to catch the exception and role back to the previous code, namely use the VARCHAR type when setting null.  This would always be thrown by the Oracle driver, severely slowing it down. 

So, I would suggest we hold off putting this into the next release until we have a better solution.

> fillStatement setNull bug with the Derby JDBC driver
> ----------------------------------------------------
>
>          Key: DBUTILS-31
>          URL: http://issues.apache.org/jira/browse/DBUTILS-31
>      Project: Commons DbUtils
>         Type: Improvement

>     Versions: 1.0
>  Environment: Derby 10.1.2.1
>     Reporter: Francis Townsend
>      Fix For: 1.1

>
> This has been documented many times before, but I was not happy with the existing code fixes.  The following small code snippet should fix it for all conforming JDBC drivers.
>     protected void fillStatement(PreparedStatement stmt, Object[] params)
>         throws SQLException {
>         if (params == null) {
>             return;
>         }
>         ParameterMetaData pmd = stmt.getParameterMetaData();
>         for (int i = 0; i < params.length; i++) {
>             if (params[i] != null) {
>                 stmt.setObject(i + 1, params[i]);
>             } else {
>                 stmt.setNull(i + 1, pmd.getParameterType(i + 1));
>             }
>         }
>     }
> The only difference is that you get the parameter meta data and pass that type information to the setNull method.  This should neatly fix this problem, with a very slight additional overhead.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (DBUTILS-31) fillStatement setNull bug with the Derby JDBC driver

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DBUTILS-31?page=all ]

Henri Yandell updated DBUTILS-31:
---------------------------------

    Fix Version: 1.1

Evaluate for 1.1.

> fillStatement setNull bug with the Derby JDBC driver
> ----------------------------------------------------
>
>          Key: DBUTILS-31
>          URL: http://issues.apache.org/jira/browse/DBUTILS-31
>      Project: Commons DbUtils
>         Type: Improvement

>     Versions: 1.0
>  Environment: Derby 10.1.2.1
>     Reporter: Francis Townsend
>      Fix For: 1.1

>
> This has been documented many times before, but I was not happy with the existing code fixes.  The following small code snippet should fix it for all conforming JDBC drivers.
>     protected void fillStatement(PreparedStatement stmt, Object[] params)
>         throws SQLException {
>         if (params == null) {
>             return;
>         }
>         ParameterMetaData pmd = stmt.getParameterMetaData();
>         for (int i = 0; i < params.length; i++) {
>             if (params[i] != null) {
>                 stmt.setObject(i + 1, params[i]);
>             } else {
>                 stmt.setNull(i + 1, pmd.getParameterType(i + 1));
>             }
>         }
>     }
> The only difference is that you get the parameter meta data and pass that type information to the setNull method.  This should neatly fix this problem, with a very slight additional overhead.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


[jira] Updated: (DBUTILS-31) fillStatement setNull bug with the Derby JDBC driver

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DBUTILS-31?page=all ]

Henri Yandell updated DBUTILS-31:
---------------------------------

    Fix Version/s:     (was: 1.1)

> fillStatement setNull bug with the Derby JDBC driver
> ----------------------------------------------------
>
>                 Key: DBUTILS-31
>                 URL: http://issues.apache.org/jira/browse/DBUTILS-31
>             Project: Commons DbUtils
>          Issue Type: Improvement
>    Affects Versions: 1.0
>         Environment: Derby 10.1.2.1
>            Reporter: Francis Townsend
>
> This has been documented many times before, but I was not happy with the existing code fixes.  The following small code snippet should fix it for all conforming JDBC drivers.
>     protected void fillStatement(PreparedStatement stmt, Object[] params)
>         throws SQLException {
>         if (params == null) {
>             return;
>         }
>         ParameterMetaData pmd = stmt.getParameterMetaData();
>         for (int i = 0; i < params.length; i++) {
>             if (params[i] != null) {
>                 stmt.setObject(i + 1, params[i]);
>             } else {
>                 stmt.setNull(i + 1, pmd.getParameterType(i + 1));
>             }
>         }
>     }
> The only difference is that you get the parameter meta data and pass that type information to the setNull method.  This should neatly fix this problem, with a very slight additional overhead.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org