Max Max - 1 year ago 138
Groovy Question

Setting fetchSize in groovy Sql

I am using groovy sql (2.4.4). But I could not figure out how to set fetchSize and scroll the results.

I use

but queries with
returns all the data at the same time and this is really slow. I want to fetch the data like we do in normal jdbc queries.

Setting maxRows is not really an option because I have to query too many times, but fetchSize would be a good option.

In groovy sql documentation( I see that:

A facade over Java's normal JDBC APIs providing greatly simplified resource management and result set handling.

But no information given about fetching.
How can I set fetchSize ?

Thank You!

Answer Source

For fetchSize, this seems to be the only option,

An example here,

 sql.withStatement { stmt -> stmt.fetchSize = 50 }

For maxResult, there are few options available,

  • use overloaded rows() method that takes a maxRows param, or
  • you could use, asList() method that takes a maxRows param, or
  • use eachRow() that takes a maxRows param

NB: There are quite a number of overloaded methods named rows(..), asList(..), and eachRow(..).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download