ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erik Hatcher" <jakarta-...@ehatchersolutions.com>
Subject Re: [PATCH] example code in Javadoc of JDBCTask
Date Fri, 26 Apr 2002 18:37:58 GMT
applied.  it doesn't look so good in the Javadoc HTML though... but its
better than it not being there!

    Erik


----- Original Message -----
From: "Nick Chalko" <nick@chalko.com>
To: "Ant Developers List" <ant-dev@jakarta.apache.org>
Sent: Friday, April 26, 2002 2:08 PM
Subject: [PATCH] example code in Javadoc of JDBCTask


> 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:nick@chalko.com">Nick Chalko</a>
>   * @author <a href="mailto:jeff@custommonkey.org">Jeff Martin</a>
>   * @author <A href="mailto:gholam@xtra.co.nz">Michael McCallum</A>
>
>


----------------------------------------------------------------------------
----


> --
> To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message