我在 Grails 服务中有这个 Groovy 伪脚本:
sql.eachRow("""
select id, col1, col2
from mytab
where col1 is null or col2 is null
"""
){
... some code to produce c1, c2 here ...
sql.execute("""
update mytab
set col1 = ${c1}, col2 = ${c2}
where id = it.id
""")
}
问题是更新仅在 eachRow 循环结束时提交给 DB。我想在 sql.execute 调用中准确提交更新。
我尝试在 sql.eachRow 之前插入 sql.resultSetConcurrency = GroovyResultSet.CONCUR_UPDATABLE,但更新仅在循环结束后继续提交。在 sql.execute() 之后也称为 sql.commit(),同样没有成功。
Sql 连接来自 DBCP Tomcat 数据源,访问 Oracle 8.1.7 数据库。
谢谢!