问题
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