Commons DbUtils
  1. Commons DbUtils
  2. DBUTILS-1

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

    Details

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

      Operating System: Windows 2000
      Platform: PC

      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()); }

      }

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

        Activity

        Henri Yandell made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Henri Yandell made changes -
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Henri Yandell made changes -
        Attachment Proposed-DBUTILS-1.patch [ 12344155 ]
        Alan B. Canon made changes -
        Attachment patch-DBUTILS-1-and-3.txt [ 12344111 ]
        Henri Yandell made changes -
        Bugzilla Id 38963
        Fix Version/s 1.1 [ 12311973 ]
        Henri Yandell made changes -
        Affects Version/s 1.1.0 [ 12311715 ]
        Henri Yandell made changes -
        Component/s DbUtils [ 12311110 ]
        Assignee Jakarta Commons Developers Mailing List [ commons-dev@jakarta.apache.org ]
        Affects Version/s 1.1.0 [ 12311676 ]
        Project Commons [ 12310458 ] Commons DbUtils [ 12310470 ]
        Key COM-2825 DBUTILS-1
        Henri Yandell made changes -
        Field Original Value New Value
        issue.field.bugzillaimportkey 38963 12342977
        Xinyi-Huang(???) created issue -

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development