Ant 任务检查数据库(连接)是否存在?
ANT 是否有可能在不导致构建失败的情况下检查数据库(连接)是否存在?
例如:
<target name="check-database-available">
<sql
classpath="${oracle.jar}" driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@${my.db.host}:${my.db.port}:${my.db.sid}"
userid="${my.db.user}"
password="${my.db.pw}"
onerror="continue" errorproperty="exit.status">
select * from dual;
</sql>
<echo message="### exit status = ${exit.status}" />
</target>
这总是会因 BUILD FAILED 而失败,并且
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
因为数据库尚不存在。将“onerror”设置为“继续”并检查“errorproperty”将不起作用,因为任务似乎没有执行。
is there a possibility in ANT to check whether a database (connection) exists or not without failing the build?
For example:
<target name="check-database-available">
<sql
classpath="${oracle.jar}" driver="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@${my.db.host}:${my.db.port}:${my.db.sid}"
userid="${my.db.user}"
password="${my.db.pw}"
onerror="continue" errorproperty="exit.status">
select * from dual;
</sql>
<echo message="### exit status = ${exit.status}" />
</target>
This will always fail with BUILD FAILED and
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
because the db does not exist yet. Setting "onerror" to "continue" and checking the "errorproperty" won't work as the task seems not to be executed.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 Ant v 1.8.0 开始,您可以将
failOnConnectionError
属性与 SQL 任务一起使用。描述如下:
看起来它可以解决你的问题。
Starting with Ant v 1.8.0 you can use the
failOnConnectionError
attribute with the SQL Task.The description reads as follows:
That looks like it would solve your problem.
这是设置 db.present 属性的解决方法(checkpresence.sql 是一个简单的 select 语句)
Here is a workaround which sets a db.present property (checkpresence.sql is a simple select statement)