How to reuse the same connection with a Spring's JdbcTemplate?

后端 未结 6 683
轮回少年
轮回少年 2020-12-13 07:02

I have the following code:


    @Test
    public void springTest() throws SQLException{
        //Connect to the DB.
        DriverManagerDataSource dataSou         


        
6条回答
  •  心在旅途
    2020-12-13 07:05

    You need the calls to be wrapped in a single transaction. Typically you'd do this with Spring's AOP + @Transactional annotation in an application. You can also do it programmatically with a PlatformTranactionManager, a TransactionTemplate and wrapping the code to execute in a TransactionCallback. See the transaction documentation.

提交回复
热议问题