commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alan B. Canon (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DBUTILS-1) [dbutils] BeanListHandler and BeanHandler fail to support java.sql.Date()
Date Fri, 03 Nov 2006 16:51:17 GMT
    [ http://issues.apache.org/jira/browse/DBUTILS-1?page=comments#action_12447007 ] 
            
Alan B. Canon commented on DBUTILS-1:
-------------------------------------

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

> [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: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message