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

后端 未结 6 674
轮回少年
轮回少年 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:24

    Looking at the Spring's code this is my understanding at a high level.

    You are creating a DriverManagerDataSource. This internally uses DataSourceUtils to get a connection. And it only reuses the connection if there is an active transaction in progress. So if you run both the executes in a single transaction then it will use the same connection. Or you can also use pooling with 1 connection so that a single connection is created and reused.

提交回复
热议问题