> 2. DBUtils - These sound real neat and I'd really like to use them, but
> I can't find any decent documentation to get a beginner started. The
> example page (http://jakarta.apache.org/commons/dbutils/examples.html)
> may be enough to remind a developer how things work, but it's rough for
> me because it leaves alot of questions and guessing.
I'll look at adding more examples soon but this is a community effort so
feel free to open a bugzilla enhancement ticket with a patch in cvs diff
-u format on the examples.
Questions for different commons components should be sent in separate
emails with the component name prefixed on the subject line like [dbutils]
or [dbcp] so that people can filter messages accordingly.
David
>
> I've used the JOCLPoolingDriverExample.java from DBCP as a basis for my
> playing with the Utils. Following the directions on the example page, I
> wasn't able to get it to work. Nor do I really understand the way its
> supposed to work.
>
> 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.
> Obviously, I'm confused and couldn't find anything to help. The only way
>
> I got it to work was as follows:
>
> import java.sql.DriverManager;
> import java.sql.Connection;
> import java.sql.Statement;
> import java.sql.ResultSet;
> import java.sql.SQLException;
> import java.util.ArrayList;
> import java.util.Iterator;
>
> import org.apache.commons.dbutils.QueryRunner;
> import org.apache.commons.dbutils.ResultSetHandler;
> import org.apache.commons.dbutils.handlers.BeanHandler;
>
> public class JOCLPoolingDriverExample {
>
> public static void main(String[] args) {
>
> Connection conn = null;
> Statement stmt = null;
> ResultSet rset = null;
>
> try {
> System.out.println("Creating connection.");
> conn =
> DriverManager.getConnection("jdbc:apache:commons:dbcp:/db");
>
> QueryRunner runner = new QueryRunner();
> ResultSetHandler h = new BeanHandler(OrderBean.class) {
> public Object handle(ResultSet rs) throws SQLException {
>
> //OrderBean orderBean = new OrderBean();
> ArrayList orders = new ArrayList();
>
> while(rs.next())
> {
> OrderBean orderBean = new OrderBean();
> orderBean.setOrderId(rs.getString(1));
> orderBean.setTotalAmount(rs.getString(2));
> orders.add(orderBean);
> }
>
> return orders;
> }
> };
>
> ArrayList p =
> (ArrayList)runner.query(conn, "SELECT ORDER_ID,
> TOTAL_AMT FROM ORDERS", h);
>
> Iterator iter = p.iterator();
> while(iter.hasNext())
> {
> System.out.println((OrderBean)iter.next());
> }
> } catch(SQLException e) {
> e.printStackTrace();
> } finally {
> try { rset.close(); } catch(Exception e) { }
> try { stmt.close(); } catch(Exception e) { }
> try { conn.close(); } catch(Exception e) { }
> }
> }
> }
>
>
> I doubt this is at all correct as its really not doing anything for me.
> It's just as much work. From the example, it infers that the
> ResultSetHandler class will work some magic in dumping your query into
> an Object. Can anyone help?
>
> Thanks,
> Mike Zatko
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
__________________________________
Do you Yahoo!?
Free Pop-Up Blocker - Get it now
http://companion.yahoo.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]