我可以在属性直接保存结果SQL查询的蚂蚁 [英] Can i save result of a sql query in a property directly in ant
本文介绍了我可以在属性直接保存结果SQL查询的蚂蚁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要SQL查询结果保存到蚂蚁的属性。我知道我可以通过文件做到这一点。但是我可以通过直接声明一个属性并将其分配给一个属性。
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.
例如:从表名SELECT COUNT(colname需要)
所以我要计数值分配给属性。
So i want to assign count value to a property.
推荐答案
使用标准的SQL蚂蚁任务不能做到这一点。
Can't do this using the standard ant sql task.
使用一个 Groovy脚本来设置属性,如下所示:
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>
这篇关于我可以在属性直接保存结果SQL查询的蚂蚁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文