本文介绍了如何在Groovy中为SQL查询配置超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b $ pre $ def $ db $ Sql.newInstance(jdbc:mysql: // $ {mysql_host}:3306 / $ {dbName},
user,pass,'com.mysql.jdbc.Driver')
db.eachRow(query){row - >
//对行做些事
}
解决方案我认为正确的方法是这样的:
$ b $ pre $
$ b $ pre $
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的地方,但我希望这可以给你一个想法。
How do I create a timeout for this operation: ?
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
}
解决方案
I believe the correct way would be something like this:
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
} )
of course, this is where I'd used Oracle, but I hope this can give you an idea.
这篇关于如何在Groovy中为SQL查询配置超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!