diff --git a/WHATSNEW b/WHATSNEW
index d16197e51..0a785878e 100644
--- a/WHATSNEW
+++ b/WHATSNEW
@@ -832,6 +832,10 @@ Other changes:
* Ant now builds against commons-net 2.0 as well.
Bugzilla Report 47669.
+ * A new nested element connectionProperty of
Since Ant 1.8.0
+Use nested <connectionProperty>
elements to
+ specify additional JDBC properties that need to be set when
+ connecting to the database.
Attribute | +Description | +Required | +
name | +Name of the property | +Yes | +
value | +Value of the property | +Yes | +
<sql driver="org.database.jdbcDriver" @@ -310,6 +333,21 @@ href="../using.html#path">PATH like structure and can also be set via a nest org.database.jdbcDriver and executes the SQL statements contained within the file data.sql ++ +<sql + driver="org.database.jdbcDriver" + url="jdbc:database-url" + userid="sa" + password="pass" + src="data.sql"> + <connectionProperty name="internal_logon" value="SYSDBA"> +</sql> +Connects to the database given in url as the sa user using +the org.database.jdbcDriver and executes the SQL statements contained +within the file data.sql. Also sets the +property internal_logon to the value SYSDBA.
+<sql driver="org.database.jdbcDriver" url="jdbc:database-url" diff --git a/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java b/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java index 974c3e4bd..c0275a7cc 100644 --- a/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/JDBCTask.java @@ -22,9 +22,12 @@ import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.Driver; import java.sql.SQLException; +import java.util.ArrayList; import java.util.Hashtable; -import java.util.Properties; +import java.util.Iterator; +import java.util.List; import java.util.Locale; +import java.util.Properties; import org.apache.tools.ant.AntClassLoader; import org.apache.tools.ant.BuildException; @@ -148,6 +151,13 @@ public abstract class JDBCTask extends Task { */ private boolean failOnConnectionError = true; + /** + * Additional properties to put into the JDBC connection string. + * + * @since Ant 1.8.0 + */ + private List/**/ connectionProperties = new ArrayList(); + /** * Sets the classpath for loading the driver. * @param classpath The classpath to set @@ -305,6 +315,15 @@ public abstract class JDBCTask extends Task { return loader; } + /** + * Additional properties to put into the JDBC connection string. + * + * @since Ant 1.8.0 + */ + public void addConnectionProperty(Property var) { + connectionProperties.add(var); + } + /** * Creates a new Connection as using the driver, url, userid and password * specified. @@ -332,6 +351,22 @@ public abstract class JDBCTask extends Task { Properties info = new Properties(); info.put("user", getUserId()); info.put("password", getPassword()); + + for (Iterator props = connectionProperties.iterator(); + props.hasNext(); ) { + Property p = (Property) props.next(); + String name = p.getName(); + String value = p.getValue(); + if (name == null || value == null) { + log("Only name/value pairs are supported as connection" + + " properties.", Project.MSG_WARN); + } else { + log("Setting connection property " + name + " to " + value, + Project.MSG_VERBOSE); + info.put(name, value); + } + } + Connection conn = getDriver().connect(getUrl(), info); if (conn == null) {