Since JDBCTask is designed to be extended it should include example code.


Index: src/main/org/apache/tools/ant/taskdefs/JDBCTask.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java,v
retrieving revision 1.1
diff -u -r1.1 JDBCTask.java
--- src/main/org/apache/tools/ant/taskdefs/JDBCTask.java        26 Apr 2002 
00:24:05 -0000      1.1
+++ src/main/org/apache/tools/ant/taskdefs/JDBCTask.java        26 Apr 2002 
18:04:54 -0000
@@ -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 =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>

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

Reply via email to