Managing Database Connectivity in Spring

Do I need to explicitly manage database resources when using the Spring Framework .. like to close all open connections, etc.

I read that Spring frees the developer from such coding of boiler tables ...

This is the answer to the error I get in the Spring web application:

org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to get JDBC connection; nested The exception is java.sql.SQLException: ORA-00020: maximum number of processes (150) exceeded

jdbcTemplateconfigured in the xml file, and the DAO implementation has a link to this jdbcTemplatebean, which is used to query the database.

+3
source share
5

Spring Framework, , ..?

Spring, ​​ JbdcTemplate, Spring , , .

, ( applicationContext.xml), ( , ?), -. , : destroy-method="close", ? - :

 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">

destroy .

+2

. spring? JdbcTemplate ? spring?

0

, Spring

Spring, . JdbcTemplate , fire-and-forget, - JDBC (, , ..). , getConnection(), - releaseConnection().

ORA-00020: (150)

? , , , ( 150). , .

0

: "jdbcTemplate XML ". jdbcTemplate , spring.

, , jdbcTemplate bean spring, , , , spring applicationContext, .

0

20 . db. destory-method bean ( " " ), requst. (: JdbcDaoSupport dao).

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);
        }
    }
0
source

Source: https://habr.com/ru/post/1732475/


All Articles