How to set autocommit to false in spring jdbc template

前端 未结 7 1834
天命终不由人
天命终不由人 2020-12-08 21:01

Currently I\'m setting autocommit to false in spring through adding a property to a datasource bean id like below :

   

        
7条回答
  •  感情败类
    2020-12-08 21:16

    after 5 years still a valid question, i resolved my issue in this way :

    1. set a connection with connection.setAutoCommit(false);
    2. create a jbc template with that connection;
    3. do your work and commit.
        Connection connection = dataSource.getConnection();
        connection.setAutoCommit(false);
        JdbcTemplate jdbcTemplate = 
        new  JdbcTemplate(newSingleConnectionDataSource(connection, true));
        // ignore case in mapping result
        jdbcTemplate.setResultsMapCaseInsensitive(true);
        // do your stuff
        connection.commit();
    

提交回复
热议问题