我对groovy比较新,所以我不确定我是否正确行事
我在循环中运行查询以找到最小值,如果该最小值等于12,则打印它
connection.eachRow(query) {
def errorstate = false
if (y < x && y !=0)
{
errorstate = true
x = y ---> if y is less than x then set x = value of y
}
/* if y is greater then the value of x will not change */
if (x == 12)
printf ("%-30s\t%-20s\t\n" , name,y)
}
提前致谢!!
答案 0 :(得分:0)
试试这个:
connection.eachRow(query) {
def errorstate = false
if (y != 0)
{
errorstate = y < x
x = Math.min(x, y)
}
}
/* if y is greater then the value of x will not change */
if (x == 12)
printf "%-30s\t%-20s\t\n" , name, y
这假设eachRow
将在返回之前调用每行上给出的闭包。我不知道是否是这种情况,因为您没有发布您正在使用的库。
很可能eachRow
将在一个单独的线程中运行闭包,在运行任何循环之前立即返回。查看eachRow
的文档,了解是否属于这种情况。