No one mentioned this, but you can also use the ant sql task. Below is the ant macro I'm using. A macro depends on many properties that are read from a .properties file over the years when I used variants of this macro with Postgres, Oracle, MySQL, DB2, MS SQL Server
<macrodef name="oracle-admin"> <attribute name="sqlfile" /> <attribute name="onerror" default="continue" /> <attribute name="autocommit" default="true" /> <attribute name="expandproperties" default="true" /> <attribute name="delimitertype" default="normal" /> <sequential> <sql driver="oracle.jdbc.OracleDriver" url="${oracle.url}" userid="${oracle.db.admin.user}" password="${oracle.db.admin.password}" classpath="${oracle.jdbc.jar}" expandproperties="@{expandproperties}" keepformat="true" delimitertype="@{delimitertype}" rdbms="oracle" onerror="@{onerror}" print="true" autocommit="@{autocommit}"> <transaction src="@{sqlfile}"> </transaction> </sql> </sequential> </macrodef>
The macro is loaded by the SQL file, the sql file can contain ant properties, which will be replaced by the values ββfrom the properties file.
CREATE ROLE ${postgres.db.user} WITH LOGIN PASSWORD '${postgres.db.password}'; CREATE DATABASE ${postgres.db.database} OWNER ${postgres.db.user} ENCODING='UTF8';
source share