本文介紹了用于檢查數據庫(連接)是否存在的 Ant 任務?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
在 ANT 中是否有可能在不導致構建失敗的情況下檢查數據庫(連接)是否存在?
is there a possibility in ANT to check whether a database (connection) exists or not without failing the build?
例如:
<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 和
This will always fail with BUILD FAILED and
java.sql.SQLException: ORA-01017: invalid username/password; logon denied
因為數據庫還不存在.將onerror"設置為continue"并檢查errorproperty"將不起作用,因為任務似乎沒有被執行.
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.
推薦答案
這是一個設置 db.present 屬性的解決方法(checkpresence.sql 是一個簡單的選擇語句)
Here is a workaround which sets a db.present property (checkpresence.sql is a simple select statement)
<target name="check-db-presence">
<echo message="Checking database presence at: ${db.url}"/>
<delete file="tmp/db.present"/>
<sql driver="${db.driver}" url="${db.url}"
userid="${db.userName}" password="${db.password}"
failOnConnectionError="false" onerror="continue" warningproperty="db.empty" errorproperty="db.empty"
src="scripts/${db.platform}/checkpresence.sql"
print="true" output="tmp/db.present"/>
<condition property="db.present">
<available file="tmp/db.present"/>
</condition>
</target>
這篇關于用于檢查數據庫(連接)是否存在的 Ant 任務?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!