Thanks
Tatu Vanhanen wrote:
I must confess that I have not used DBUtils and am not a pro in DBCP but anyway here comes what I found.
lled printDriverStats() and shutdownDriver(). The former uses what
appears to be a protected method called getConnectionPool(String) in the
Class PoolingDriver.
There appears to be a method getPool(String), although that is deprecated. The javadoc says that it is to be replaced with the protected getConnectionPool(String), but for now the getPool is the one to use.
The latter has a similar problem with the PoolingDriver Class except
instead of being protected, eclipse tells me its undefined. The method
is closePool(String).
Did not find a closePool(String) in PoolingDriver, but you can probably call ObjectPool.close() to close the pool. The ObjectPool is returned from getPool(String).
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 =)
- Tatu V.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
