diff --git a/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java b/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java index 7ef8fe7b1..55534ea31 100644 --- a/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java @@ -70,7 +70,57 @@ import java.util.Properties; /** * Handles JDBC configuration needed by SQL type tasks. - * + *

+ * The following example class prints the contents of the first column of each row in TableName. + *

+ *
+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;
+    }
+
+}
+
+ 
+
+ + * @author Nick Chalko * @author Jeff Martin * @author Michael McCallum @@ -437,4 +487,4 @@ public abstract class JDBCTask extends Task { return version; } -} \ No newline at end of file +}