Uploaded image for project: 'Commons DbUtils'
  1. Commons DbUtils
  2. DBUTILS-31

fillStatement setNull bug with the Derby JDBC driver

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.0
    • Fix Version/s: 1.2
    • Labels:
      None
    • Environment:

      Derby 10.1.2.1

      Description

      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.

        Attachments

          Activity

            People

            • Assignee:
              dfabulich Dan Fabulich
              Reporter:
              ftownsend Francis Townsend
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: