org.apache.tools.ant.taskdefs
Class SQLExec

java.lang.Object
  |
  +--org.apache.tools.ant.Task
        |
        +--org.apache.tools.ant.taskdefs.SQLExec

public class SQLExec
extends Task

Reads in a text file containing SQL statements seperated with semicolons and executes it in a given db. Both -- and // maybe used as comments.

Author:
Jeff Martin

Inner Class Summary
static class SQLExec.OnError
          Enumerated attribute with the values "continue", "stop" and "abort" for the onerror attribute.
 class SQLExec.Transaction
          Contains the definition of a new transaction element.
 
Fields inherited from class org.apache.tools.ant.Task
description, location, project, target, taskName, taskType, wrapper
 
Constructor Summary
SQLExec()
           
 
Method Summary
 void addText(java.lang.String sql)
          Set the sql command to execute
 Path createClasspath()
          Create the classpath for loading the driver.
 SQLExec.Transaction createTransaction()
          Set the sql command to execute
protected  void execSQL(java.lang.String sql, java.io.PrintStream out)
          Exec the sql statement.
 void execute()
          Load the sql file and then execute it
protected  boolean isValidRdbms(java.sql.Connection conn)
          Verify if connected to the correct RDBMS
protected  void printResults(java.io.PrintStream out)
          print any results in the statement.
protected  void runStatements(java.io.Reader reader, java.io.PrintStream out)
           
 void setAutocommit(boolean autocommit)
          Set the autocommit flag for the DB connection.
 void setClasspath(Path classpath)
          Set the classpath for loading the driver.
 void setClasspathRef(Reference r)
          Set the classpath for loading the driver using the classpath reference.
 void setDriver(java.lang.String driver)
          Set the JDBC driver to be used.
 void setOnerror(SQLExec.OnError action)
          Set the action to perform onerror
 void setOutput(java.io.File output)
          Set the output file.
 void setPassword(java.lang.String password)
          Set the password for the DB connection.
 void setPrint(boolean print)
          Set the print flag.
 void setRdbms(java.lang.String vendor)
          Set the rdbms required
 void setShowheaders(boolean showheaders)
          Set the showheaders flag.
 void setSrc(java.io.File srcFile)
          Set the name of the sql file to be run.
 void setUrl(java.lang.String url)
          Set the DB connection url.
 void setUserid(java.lang.String userId)
          Set the user name for the DB connection.
 void setVersion(java.lang.String version)
          Set the version required
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getProject, getRuntimeConfigurableWrapper, getTaskName, init, log, log, maybeConfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SQLExec

public SQLExec()
Method Detail

setClasspath

public void setClasspath(Path classpath)
Set the classpath for loading the driver.

createClasspath

public Path createClasspath()
Create the classpath for loading the driver.

setClasspathRef

public void setClasspathRef(Reference r)
Set the classpath for loading the driver using the classpath reference.

setSrc

public void setSrc(java.io.File srcFile)
Set the name of the sql file to be run.

addText

public void addText(java.lang.String sql)
Set the sql command to execute

createTransaction

public SQLExec.Transaction createTransaction()
Set the sql command to execute

setDriver

public void setDriver(java.lang.String driver)
Set the JDBC driver to be used.

setUrl

public void setUrl(java.lang.String url)
Set the DB connection url.

setUserid

public void setUserid(java.lang.String userId)
Set the user name for the DB connection.

setPassword

public void setPassword(java.lang.String password)
Set the password for the DB connection.

setAutocommit

public void setAutocommit(boolean autocommit)
Set the autocommit flag for the DB connection.

setPrint

public void setPrint(boolean print)
Set the print flag.

setShowheaders

public void setShowheaders(boolean showheaders)
Set the showheaders flag.

setOutput

public void setOutput(java.io.File output)
Set the output file.

setRdbms

public void setRdbms(java.lang.String vendor)
Set the rdbms required

setVersion

public void setVersion(java.lang.String version)
Set the version required

setOnerror

public void setOnerror(SQLExec.OnError action)
Set the action to perform onerror

execute

public void execute()
             throws BuildException
Load the sql file and then execute it
Overrides:
execute in class Task
Following copied from class: org.apache.tools.ant.Task
Throws:
BuildException - if someting goes wrong with the build

runStatements

protected void runStatements(java.io.Reader reader,
                             java.io.PrintStream out)
                      throws java.sql.SQLException,
                             java.io.IOException

isValidRdbms

protected boolean isValidRdbms(java.sql.Connection conn)
Verify if connected to the correct RDBMS

execSQL

protected void execSQL(java.lang.String sql,
                       java.io.PrintStream out)
                throws java.sql.SQLException
Exec the sql statement.

printResults

protected void printResults(java.io.PrintStream out)
                     throws java.sql.SQLException
print any results in the statement.


Copyright ? 2000 Apache Software Foundation. All Rights Reserved.