Database connection management in Spring

后端 未结 5 1933
栀梦
栀梦 2021-01-21 09:25

Do we have to explicitly manage database resources when using Spring Framework.. liking closing all open connections etc?

I have read that Spring relieves developer from

5条回答
  •  猫巷女王i
    2021-01-21 09:58

    My hosing provide only 20 connection. I done by manually close the connection on every request to db. I not declared a destory-method in bean(this not worked "i dont know why"), but i done in every requst call. (Hint : extends JdbcDaoSupport in dao class).

    public void cleanUp() {
            try {
                if (!this.getJdbcTemplate().getDataSource().getConnection().isClosed()) {
                    this.getJdbcTemplate().getDataSource().getConnection().close();
                }
            } catch (Exception e) {
                Logger.getLogger(myDAOImpl.class.getName()).log(Level.SEVERE, null, e);
            }
        }
    

提交回复
热议问题