ehatcher    02/04/26 11:37:27

  Modified:    src/main/org/apache/tools/ant/taskdefs JDBCTask.java
  Log:
  adding example of usage.  patch submitted by Nick Chalko
  
  Revision  Changes    Path
  1.2       +52 -2     
jakarta-ant/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java
  
  Index: JDBCTask.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JDBCTask.java     26 Apr 2002 00:24:05 -0000      1.1
  +++ JDBCTask.java     26 Apr 2002 18:37:26 -0000      1.2
  @@ -70,7 +70,57 @@
   
   /**
    * Handles JDBC configuration needed by SQL type tasks.
  - *
  + * <p>
  + * The following example class prints the contents of the first column of 
each row in TableName.
  + *</p>
  + *<code><pre>
  +package examples;
  +import java.sql.Connection;
  +import java.sql.ResultSet;
  +import java.sql.SQLException;
  +import java.sql.Statement;
  +
  +import org.apache.tools.ant.BuildException;
  +import org.apache.tools.ant.taskdefs.JDBCTask;
  +
  +public class SQLExampleTask extends JDBCTask {       
  +
  +    private String tableName;
  +
  +    public void execute() throws BuildException {
  +        Connection conn = getConnection();
  +        Statement stmt=null;
  +        try {
  +            if (tableName == null ) {
  +                throw new BuildException("TableName must be 
specified",location);
  +            }             
  +            String sql = "SELECT * FROM "+tableName;
  +            stmt= conn.createStatement();
  +            ResultSet rs = stmt.executeQuery(sql);
  +            while (rs.next()) {
  +                log(rs.getObject(1).toString());
  +            }
  +        } catch (SQLException e) {
  +        
  +        } finally {
  +            if (stmt != null) {
  +                try {stmt.close();}catch (SQLException ingore){}
  +            }
  +            if (conn != null) {
  +                try {conn.close();}catch (SQLException ingore){}
  +            }
  +        }
  +    }
  +    public void setTableName(String tableName) {
  +        this.tableName = tableName;
  +    }
  +
  +}
  +
  + 
  +</pre></code>
  +
  +
    * @author <a href="mailto:[EMAIL PROTECTED]">Nick Chalko</a>
    * @author <a href="mailto:[EMAIL PROTECTED]">Jeff Martin</a>
    * @author <A href="mailto:[EMAIL PROTECTED]">Michael McCallum</A>
  @@ -437,4 +487,4 @@
           return version;
       }
   
  -}
  \ No newline at end of file
  +}
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to