Issue Details (XML | Word | Printable)

Key: DBUTILS-1
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Xinyi-Huang(???)
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons DbUtils

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

Created: 14/Mar/06 10:23 PM   Updated: 02/Jan/08 07:29 AM
Return to search
Component/s: None
Affects Version/s: None
Fix Version/s: 1.1

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works patch-DBUTILS-1-and-3.txt 2006-11-01 04:03 PM Alan B. Canon 1.0 kB
Text File Licensed for inclusion in ASF works Proposed-DBUTILS-1.patch 2006-11-02 06:17 AM Henri Yandell 1 kB
Environment:
Operating System: Windows 2000
Platform: PC

Bugzilla Id: 38963
Resolution Date: 03/Nov/06 05:03 PM


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



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
No work has yet been logged on this issue.