Can i save result of a sql query in a property directly in ant

时间秒杀一切 提交于 2019-12-08 04:57:08

问题


I want to save the sql query result into a property in ant. I know i can do it through a file. But can i assign it to a property by directly declaring a property.

eg: select count(colname) from tablename.

So i want to assign count value to a property.


回答1:


Can't do this using the standard ant sql task.

Use a groovy script to set the property as follows:

<target name="query">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <groovy>
    import groovy.sql.Sql

    def sql = Sql.newInstance(properties."db.url", properties."db.user", properties."db.pass", properties."db.driver")
    def row = sql.firstRow("SELECT count(*) from example1")

    properties."row.count" = row[0]
    </groovy>
</target>

<target name="result" depends="query">
    <echo message="Row count: ${row.count}"/>
</target>


来源:https://stackoverflow.com/questions/8800812/can-i-save-result-of-a-sql-query-in-a-property-directly-in-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!