在NamedParameterJdbcTemplate.batchUpdate中禁用自动提交 [英] Disabling auto-commit in NamedParameterJdbcTemplate.batchUpdate

查看:1035
本文介绍了在NamedParameterJdbcTemplate.batchUpdate中禁用自动提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NamedParameterJdbcTemplate.batchUpdate批量更新数据库表,但是我想禁用auto-commit并手动执行提交.

I am doing a batch update into my DB table using NamedParameterJdbcTemplate.batchUpdate, but I would like to disable auto-commit and perform the commit manually.

我可以将connection对象的自动提交模式设置为关闭,但是不确定如何使用NamedParameterJdbcTemplate对象执行相同的操作.

I can set auto-commit mode off from the connection object, but not sure how to do the same using NamedParameterJdbcTemplate object.

推荐答案

我已经使用它有一个execute方法,我在此函数的回调内部执行业务逻辑.

It has an execute method and I do the business logic inside a callback in this function.

transTemplate.execute( new TransactionCallbackWithoutResult()
        {       
                @Override
                protected void doInTransactionWithoutResult( TransactionStatus status)
                {
                    status.setRollbackOnly();
                    //business logic
                }

        });

这篇关于在NamedParameterJdbcTemplate.batchUpdate中禁用自动提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆