<target name="create-db-tables" depends="initialize">
<fail message="Missing property [datasource.url]." unless="datasource.url" />
<fail message="Missing property [db.user]." unless="db.user" />
<fail message="Missing property [db.password]." unless="db.password" />
<fail message="Missing property [db.sql.driver]." unless="db.sql.driver" />
<sql driver="${db.sql.driver}" url="${datasource.url}" userid="${db.user}" password="${db.password}" output="${basedir}/createTable.log" onerror="continue">
<classpath>
<pathelement location="${basedir}/../lib/ojdbc.jar"/>
</classpath>
<transaction src="${basedir}/ddl/dropTables.sql" />
<transaction src="${basedir}/ddl/createTables.sql" />
</sql>
</target>
我在我的ant脚本中定义了上面的目标,它首先删除表,然后创建它们。我希望ant在删除表时忽略错误(即onerror =“continue”),但是在表创建期间发生错误时抛出异常(即onerror =“abort”)。但它在“sql”标记中采用了事务行为,因此它对所有事务都很常见。
我不想创建单独的sql标记并重复数据库详细信息。另外,我想通过文件执行sql。我怎么能通过蚂蚁来做?
答案 0 :(得分:0)
我会这样做:
classpathref
看起来像这样:
<target name="create-db-tables" depends="initialize">
<fail message="Missing property [datasource.url]." unless="datasource.url" />
<fail message="Missing property [db.user]." unless="db.user" />
<fail message="Missing property [db.password]." unless="db.password" />
<fail message="Missing property [db.sql.driver]." unless="db.sql.driver" />
<classpath id="ojdbcpath">
<pathelement location="${basedir}/../lib/ojdbc.jar"/>
</classpath>
<!--- First Drop -->
<sql driver="${db.sql.driver}" url="${datasource.url}"
userid="${db.user}" password="${db.password}"
output="${basedir}/createTable.log" onerror="continue"
classpathref="ojdbcpath">
<transaction src="${basedir}/ddl/dropTables.sql" />
</sql>
<!--- Then create -->
<sql driver="${db.sql.driver}" url="${datasource.url}"
userid="${db.user}" password="${db.password}"
output="${basedir}/createTable.log" onerror="abort"
classpathref="ojdbcpath">
<transaction src="${basedir}/ddl/createTables.sql" />
</sql>
</target>