Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling auto-commit in NamedParameterJdbcTemplate.batchUpdate

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.

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

like image 995
Shamim Hafiz - MSFT Avatar asked Nov 18 '25 00:11

Shamim Hafiz - MSFT


1 Answers

I have done my implementation using TransactionTemplate

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
                }

        });
like image 176
Shamim Hafiz - MSFT Avatar answered Nov 19 '25 12:11

Shamim Hafiz - MSFT