I am trying to read a table having five rows and columns. I have used sql.eachRow function to read eachRow and assign the value to a String. I am getting an error "Groovy:[Static type checking] - No such property: MachineName for class: java.lang.Object"
My code:
sql.eachRow('select * from [MACHINES] WHERE UpdateTime > :lastTimeRead, [lastTimeRead: Long.parseLong(lastTimeRead)])
{ row ->
def read = row.MachineName
}
but MachineName is my column name. How can i overcome this error.
Using dynamic Properties with static type checking is not possible*.
However,
eachRow
will pass aGroovyResultSet
as first parameter to theClosure
. This means thatrow
has the typeGroovyResultSet
and so you can access the value usinggetAt
should work. In groovy you can also use the
[]
-operator:which is equivalent to the first solution.
*) without a type checking extension.