0

I am using Spring JDBC and I would like to set autocommit to false only to one of the classes.

I have tried the following but the autocommit is still true when I print out the value:

getJdbcTemplate().getDataSource().getConnection().setAutoCommit(false));
getJdbcTemplate().update(UPDATE_QUERY,params);

How should I do this?

xcoder
  • 1,336
  • 2
  • 17
  • 44
  • 2
    Personally I'd have autocommit set to false across the board. Not being able to issue a rollback when something goes wrong is a risky way to play. – JonK Oct 15 '15 at 08:53
  • @JonK Thanks for your comment. I looked at this link before (http://stackoverflow.com/questions/10746377/spring-3-1-jdbctemplate-auto-commit-to-false) and where is that config file usually locate? – xcoder Oct 15 '15 at 08:57
  • you should look into transaction management with spring : http://docs.spring.io/spring/docs/current/spring-framework-reference/html/transaction.html – Keval Oct 15 '15 at 09:03
  • Depends on your app server, the answer there implies that you change the datasource config so that the connections it creates have autocommit disabled, rather than configuring spring to disable it. – JonK Oct 15 '15 at 09:03

0 Answers0