commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dgra...@apache.org
Subject cvs commit: jakarta-commons/dbutils/xdocs examples.xml
Date Fri, 19 Mar 2004 00:25:39 GMT
dgraham     2004/03/18 16:25:39

  Modified:    dbutils/xdocs examples.xml
  Log:
  Fixed first example to check for empty ResultSet.
  
  Revision  Changes    Path
  1.6       +8 -15     jakarta-commons/dbutils/xdocs/examples.xml
  
  Index: examples.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/dbutils/xdocs/examples.xml,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- examples.xml	14 Mar 2004 23:12:34 -0000	1.5
  +++ examples.xml	19 Mar 2004 00:25:39 -0000	1.6
  @@ -18,7 +18,7 @@
   <document>
   
    <properties>
  -  <title>JDBC Utility Component -- Examples</title>
  +    <title>JDBC Utility Component -- Examples</title>
    </properties>
   
   <body>
  @@ -47,6 +47,10 @@
   // first row into an Object[].
   ResultSetHandler h = new ResultSetHandler() {
       public Object handle(ResultSet rs) throws SQLException {
  +        if (!rs.next()) {
  +            return null;
  +        }
  +    
           ResultSetMetaData meta = rs.getMetaData();
           int cols = meta.getColumnCount();
           Object[] result = new Object[cols];
  @@ -77,20 +81,9 @@
   </p>
   <source>
   <![CDATA[
  -ResultSetHandler h = new ResultSetHandler() {
  -    public Object handle(ResultSet rs) throws SQLException {
  -        ResultSetMetaData meta = rs.getMetaData();
  -        int cols = meta.getColumnCount();
  -        Object[] result = new Object[cols];
  -
  -        for (int i = 0; i < cols; i++) {
  -            result[i] = rs.getObject(i + 1);
  -        }
  -
  -        return result;
  -    }
  -};
  +ResultSetHandler h = ... // Define a handler the same as above example
   
  +// No DataSource so we must handle Connections manually
   QueryRunner run = new QueryRunner();
   
   Connection conn = ... // open a connection
  @@ -100,7 +93,7 @@
   	// do something with the result
   	
   } finally {
  -    // use this helper method so we don't have to check for null
  +    // Use this helper method so we don't have to check for null
       DbUtils.close(conn);  
   }
   ]]>
  
  
  

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


Mime
View raw message