You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by yo...@apache.org on 2003/11/10 17:45:45 UTC

cvs commit: jakarta-commons/dbutils/xdocs examples.xml

yoavs       2003/11/10 08:45:45

  Added:       dbutils/xdocs examples.xml
  Log:
  Initial version of Examples page.
  
  Revision  Changes    Path
  1.1                  jakarta-commons/dbutils/xdocs/examples.xml
  
  Index: examples.xml
  ===================================================================
  <?xml version="1.0"?>
  
  <document>
  
   <properties>
    <title>JDBC Utility Component -- Examples</title>
    <author email="yoavs@apache.org">Yoav Shapira</author>
   </properties>
  
  <body>
  
  <section name="DbUtils: JDBC Utility Component Examples">
  <p>
  This page provides examples that show how the DbUtils component
  may be used.
  </p>
  </section>
  
  <section name="Basic Usage">
  <p>
  The core classes/interfaces in DbUtils are 
  <code><a href="apidocs/org/apache/commons/dbutils/QueryRunner.html">QueryRunner</a></code>
  and
  <code><a href="apidocs/org/apache/commons/dbutils/ResultSetHandler.html">ResultSetHandler</a></code>.
  The following example demonstrates how these classes are used together.
  </p>
  
  <pre>
  DataSource ds = // somehow get DataSource;
  
  // Step 1.
  QueryRunner run = new QueryRunner(ds);
  
  // Step 2.
  ResultSetHandler h = new BeanHandler(Person.class);
  
  // Step 3.
  Person p = (Person) run.query("SELECT * FROM Person WHERE name=?", "John Doe", h); 
  
  </pre>
  
  <p>Explanation</p>
  <ol>
      <li>
          Configure QueryRunner with the DataSource.
          Note that QueryRunner has methods that take a 
          java.sql.Connection so you are not required to
          use DataSources.
      </li>
      <li>
          Implement the ResultSetHandler interface or use
          one of the provided implementations.  This one converts a 
          ResultSet row into a bean.
      </li>
      <li>
          Execute the SQL statement with one replacement parameter and
          return the results in a new Person object (generated by the handler
          in step 2).
      </li>
  </ol>
  
  </section>
  
  </body>
  </document>
  
  
  
  

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