groovy sql可更新游标 - 直到游标结束才更新

时间:2012-11-13 10:44:42

标签: sql grails jdbc groovy

我在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
 """)
}

问题是更新只在每个循环结束时提交给DB。我希望在sql.execute调用时完全提交更新。

我试过插入     sql.resultSetConcurrency = GroovyResultSet.CONCUR_UPDATABLE 就在sql.eachRow之前,但更新只在循环结束后继续提交。 在sql.execute()之后也称为sql.commit(),再次没有成功。

Sql连接来自DBCP Tomcat数据源,访问Oracle 8.1.7数据库。

谢谢!

1 个答案:

答案 0 :(得分:0)

Grails服务方法调用默认情况下会自动用事务包装。如果抛出未经检查的(!)异常,则db事务将由底层Spring组件回滚。要禁用此行为,您必须使用@Transactional或指定static transactional = falseas described here