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. patch-DBUTILS-1-and-3.txt
        1.0 kB
        Alan B. Canon
      2. Proposed-DBUTILS-1.patch
        1 kB
        Henri Yandell

        Activity

        Hide
        Henri Yandell added a comment -

        svn ci -m "Enabling the bean handlers to support java.sql.Date, Time and Timestamp. #DBUTILS-1. "

        Sending src/java/org/apache/commons/dbutils/BeanProcessor.java
        Transmitting file data .
        Committed revision 470904.

        Show
        Henri Yandell added a comment - svn ci -m "Enabling the bean handlers to support java.sql.Date, Time and Timestamp. # DBUTILS-1 . " Sending src/java/org/apache/commons/dbutils/BeanProcessor.java Transmitting file data . Committed revision 470904.
        Hide
        Alan B. Canon added a comment -

        Agree with Proposed-DBUTILS-1.patch. Much nicer. Apply?

        Show
        Alan B. Canon added a comment - Agree with Proposed- DBUTILS-1 .patch. Much nicer. Apply?
        Hide
        Henri Yandell added a comment -

        I think it needs a bit more work to support java.sql.Time and Timestamp, and I think the code can be expressed a bit differently to keep things clear.

        Alan, how does the 'Proposed-DBUTILS-1.patch' that I just uploaded look to you?

        Show
        Henri Yandell added a comment - I think it needs a bit more work to support java.sql.Time and Timestamp, and I think the code can be expressed a bit differently to keep things clear. Alan, how does the 'Proposed- DBUTILS-1 .patch' that I just uploaded look to you?
        Hide
        Alan B. Canon added a comment -

        This patch also addresses DBUTILS-3. It may not work if the patch recently attached to that issue has already been applied to source.

        Show
        Alan B. Canon added a comment - This patch also addresses DBUTILS-3 . It may not work if the patch recently attached to that issue has already been applied to source.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development