Ant task to check if the database (connection) exists?

is it possible in ANT to check whether or not a database (connection) exists without a build failure?

For instance:

<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 happen with a BUILD FAILED error and

java.sql.SQLException: ORA-01017: invalid username/password; logon denied

because db does not exist yet. Setting "onerror" to "continue" and checking for "errorproperty" will not work, as the task does not seem to be running.

+3
source share
2 answers

Starting with Ant v 1.8.0, you can use the attribute failOnConnectionErrorwith an SQL task.

The description is as follows:

false, - , .

, .

+1

, db.present(checkpresence.sql - select)

<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>
+1

Source: https://habr.com/ru/post/1756926/


All Articles