You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by David Graham <gr...@yahoo.com> on 2004/03/04 02:15:13 UTC

Re: [dbutils] Does DbUtils handle boolean variables in beans?

--- Lian Liu <li...@us.ibm.com> wrote:
> Hi,
> 
> I have a question on DBUtils.  When I pass in a BeanListHandler to
> QueryRunner's runQuery method, I expect that the bean will be populated
> with the query results that I get back.  What if I have a boolean
> variable
> in the bean, and the matching field in database is a smallint type? It
> appears to me that the boolean value is always set to false even if the
> value in database is 1.  Thank you in advance.

DbUtils 1.0 uses ResultSet.getObject() to retrieve the value to set into
the bean property.  If the type returned from getObject() does not match
the bean property type, the bean's setter method is not called.  So,
what's probably happening is an integer is being returned so it doesn't
set your boolean property.

This is a common problem so we added the ColumnProcessor interface to
allow customizing this process.  The provided BasicColumnProcessor
implementation detects the type of bean property and calls the appropriate
ResultSet.get* method.  In your case it would see that it's a boolean
property and call ResultSet.getBoolean().  

Of course, if your JDBC driver doesn't convert from smallints to booleans
correctly you will still have a problem but that's outside of DbUtils'
control.

Download a nightly build to try out the new interface and let us know if
it works.  Please prefix messages to the mailing list with the component
name [dbutils] so people can filter messages easily :-).

David

> 
> thanks,
> Lian Liu
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you�re looking for faster
http://search.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org