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

[dbutils] BeanListHandler and BeanHandler fail to support java.sql.Date()

    Details

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

      Operating System: Windows 2000
      Platform: PC

    • Bugzilla Id:
      38963

      Description

      BeanListHandler or BeanHandler fail to support the java.sql.Date type when
      read from database.
      I just add some codes to callSetter the method callSetter of BeanProcessor as
      ----------------------
      else if(params[0].getName().equals("java.sql.Date")){
      value = (value==null)?null:new java.sql.Date
      (((java.util.Date)value).getTime());
      setter.invoke(target, new Object[]

      {value});
      ----------------------


      org.apache.commons.dbutils.BeanProcessor

      private void callSetter(Object target, PropertyDescriptor prop, Object value)
      throws SQLException {

      Method setter = prop.getWriteMethod();

      if (setter == null) { return; }

      Class[] params = setter.getParameterTypes();
      try {
      // Don't call setter if the value object isn't the right type
      if (this.isCompatibleType(value, params[0])) {
      setter.invoke(target, new Object[] { value });
      }else if(params[0].getName().equals("java.sql.Date")){
      value = (value==null)?null:new java.sql.Date
      (((java.util.Date)value).getTime());
      setter.invoke(target, new Object[] {value}

      );
      }

      } catch (IllegalArgumentException e)

      { throw new SQLException( "Cannot set " + prop.getName() + ": " + e.getMessage()); }

      catch (IllegalAccessException e)

      { throw new SQLException( "Cannot set " + prop.getName() + ": " + e.getMessage()); }

      catch (InvocationTargetException e)

      { throw new SQLException( "Cannot set " + prop.getName() + ": " + e.getMessage()); }

      }

        Attachments

        1. Proposed-DBUTILS-1.patch
          1 kB
          Henri Yandell
        2. patch-DBUTILS-1-and-3.txt
          1.0 kB
          Alan B. Canon

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              bluelover@gmail.com Xinyi-Huang(???)
            • Votes:
              1 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: