This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
According to conventional JDBC we can set autocommit to false before executeBatch(). When this method returns an int array we will cross check the length of array to identify the number of records affected then we will commit the transaction. But JdbcTemplate.batchUpdate(String sql, BatchPreparedStatementSetter pss) will insert the records and commits automatically then returning int array. Can I cross check the records updated with this before committing?
My first suggestion is to set the default auto commit false on the data source itself. If you are using Spring to manage your transactions (say using the @Trasactional annotation) most likely it is being set false for you anyway. If that is not the case you will need to do it via the connection.
Code like this generally smells since you should be able to let Spring manage that for you, and I cant think of a good reason to have autocommit on at all, but if you really need access to the connection you can use the DataSourceUtils class.