Ant SQL任务errorproperty示例

时间:2015-09-18 10:40:10

标签: ant

有谁知道如何使用和SQL TASK errorproperty的示例? 我想做这样的事情:

<sql
                driver="${jdbc.driver.class}"
                url="${jdbc.url}"
                userid="${db.admin.user}"
                password="${db.admin.password}"
                onerror="continue"
                autocommit="true"
                delimiter="/"
                print="true"
                failOnConnectionError="false"
                errorproperty="dberror">
            <classpath>
                <pathelement location="${jdbc.driver.location}"/>
            </classpath>
            ${query.drop}
        </sql>
<if>
<isset dberror>
do this
<else> 
do that
</if>

1 个答案:

答案 0 :(得分:1)

使用Ant&lt; 1.9.3你这样说:

<project>

 <target name="calldb"
  <sql .. errorproperty="dberror"/>

  <condition property="isdberror">
   <isset property="dberror"/>
  </condition>
 </target>  

  <target name="ifdberror" if="isdberror">
   ...
  </target>

  <target name="nodberror" unless="isdberror">
   ...
  </target>

  <!-- create target dependency chain -->
  <target name="whatever" depends="calldb,ifdberror,nodberror"/>

</project>

使用Ant&gt; = 1.9.3,你会这样:

<project
  xmlns:if="ant:if"
  xmlns:unless="ant:unless"
>

 <target name="calldb">
  <sql .. errorproperty="dberror"/>

  <!-- example, echo instead of real work .. -->
  <echo unless:blank="${dberror}">Houston, we have a problem !!</echo>
  <echo if:blank="${dberror}">Strike :-)</echo>

 </target>

</project>