tags:

views:

54

answers:

2

Hi,

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.

Thanks,

Peter

A: 

LE: Please read THIS.

thelost
Is there no way to do it purely in ANT?
Peter
I've already read the manual and I was not able to achieve the connection test I described above. That's why I posted this question.
Peter
+1  A: 

Starting with Ant v 1.8.0 you can use the failOnConnectionError attribute with the SQL Task.

The description reads as follows:

If false, will only print a warning message and not execute any statement if the task fails to connect to the database.

That looks like it would solve your problem.

ChrisH