如何为此操作创建超时:?
def db = Sql.newInstance("jdbc:mysql://${mysql_host}:3306/${dbName}", user, pass, 'com.mysql.jdbc.Driver') db.eachRow(query) { row -> // do something with the row }
我相信正确的方法将是这样的:
sql = Sql.newInstance("jdbc:oracle:thin:@localhost:1521:XE", "user", "pwd", "oracle.jdbc.driver.OracleDriver") sql.withStatement { stmt -> stmt.queryTimeout = 10 } sql.eachRow("select * from someTable", { println it } )
当然,这是我使用Oracle的地方,但是我希望这可以给您一个想法。