commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Zoetebier <john.zoeteb...@transparent.co.nz>
Subject Re: DBCP & DBUtils
Date Fri, 12 Dec 2003 09:34:15 GMT
On Fri, 12 Dec 2003 10:42:07 +0200, Tatu Vanhanen 
<tatu.vanhanen@graftor.fi> wrote:

>> I gather the QueryRunner is designed to execute an sql query and give
>> you an object you define instead of a ResultSet. The example nor the
>> apis really tell you what the ResultSetHandler is doing. And what kind
>> of bean are you supposed to setup? I mean, if you do a SELECT * on some
>> table you can get alot of rows back, but with the QueryRunner you only
>> get a single object back. And I'm guessing you define that object
>> yourself. But, is that bean supposed to represent a row of the table
>> returned from your query? If it is, how do you access all of the rows.
>
> The Object returned depends of what kind of ResultSetHandler you pass to 
> the
> query method. You can of course make your own handler (like you did), but
> there are also ready-made ones available. Look at the javadocs of
> BeanHandler, ListHandler, etc. For eaxmple, if you know that your query
> contains only one row, you can pass a BeanHandler (the default works, 
> don't
> have to implement it!) configured with the expected bean class like
> OrderBean order = (OrderBean) runner.query(conn, "SELECT ORDER_ID, 
> TOTAL_AMT
> FROM ORDERS", new BeanHandler(OrderBean.class));
>
> and voilá, you get an OrderBean back.
>
> If you want a list of OrderBean:s, use a BeanListHandler:
> List orders = (List) runner.query(conn, "SELECT ORDER_ID, TOTAL_AMT FROM
> ORDERS", new BeanListHandler(OrderBean.class));
>
> Now every item in the list is an OrderBean.
>
> No magic here; only great stuff that great folks have done for everyone 
> to
> use =)

I can see this working nicely with static tables in a database.
In case you have a table with a structure that can expand dynamically, how 
does this work.
Can DBUtils handles the dynamic table structure scenario ?
Or is there a workaround ?

-- 
John Zoetebier
Web site: http://www.transparent.co.nz

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


Mime
View raw message