commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason E Brant <jbr...@us.ibm.com>
Subject Re: [dbutils] Does DbUtils handle boolean variables in beans?
Date Mon, 15 Mar 2004 14:11:56 GMT




Using the 1.1 API (from the nightly build) and using BasicRowProcessor and
BasicColumnProcessor instead of the default in our ResultSetHandler did the
trick, without implementing anything further:
Class type = MyBean.class;
ResultSetHandler h = new BeanListHandler(type,new BasicRowProcessor(new
BasicColumnProcessor()));
queryRunner.query(queryString, h);

Thanks for your help!

Jason Brant




                                                                           
             David Graham                                                  
             <grahamdavid1980@                                             
             yahoo.com>                                                 To 
                                       Jakarta Commons Developers List     
             03/03/2004 06:15          <commons-dev@jakarta.apache.org>    
             PM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to         Re: [dbutils] Does DbUtils handle   
             "Jakarta Commons          boolean variables in beans?         
             Developers List"                                              
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           




--- Lian Liu <lianliu@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

Mime
  • Unnamed multipart/related (inline, None, 0 bytes)
View raw message