[ http://issues.apache.org/jira/browse/DBUTILS-1?page=all ]

Henri Yandell updated DBUTILS-1:
--------------------------------

    Attachment: Proposed-DBUTILS-1.patch

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?

> [dbutils] BeanListHandler and BeanHandler fail to support java.sql.Date()
> -------------------------------------------------------------------------
>
>                 Key: DBUTILS-1
>                 URL: http://issues.apache.org/jira/browse/DBUTILS-1
>             Project: Commons DbUtils
>          Issue Type: Bug
>         Environment: Operating System: Windows 2000
> Platform: PC
>            Reporter: Xinyi-Huang
>             Fix For: 1.1
>
>         Attachments: patch-DBUTILS-1-and-3.txt, Proposed-DBUTILS-1.patch
>
>
> 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());
>         }
>     }

-- 
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to