Spring JDBC模板使用调用过程时创建的新数据库用户实例

时间:2016-01-13 06:04:10

标签: spring jdbctemplate

我使用Spring Mvc Jdbc模板来调用程序和函数。但是在函数调用之后数据库连接没有关闭。每次都有新的数据库用户实例创建。可以请任何人给我解决这个大问题的解决方案。 / p>

@Autowired
@Qualifier("dbDataSource")
public DataSource dataSource;
public SimpleJdbcCall procReadData;
public PersonDTO readPersonData(Principal principal) throws SQLException {
    List<PersonDTO> personDTOList = null;
    Map<String,Object> results = null;
    procReadData = new SimpleJdbcCall(dataSource).withProcedureName("GET_PAWS_PERSON_DETAILS");
    procReadData.addDeclaredParameter(new SqlParameter("AV_USER_NAME", OracleTypes.VARCHAR));
    procReadData.addDeclaredParameter( new SqlOutParameter( "CUR_GENERIC", OracleTypes.CURSOR,new PersonRowMapper()));
    SqlParameterSource in = new MapSqlParameterSource().addValue("AV_USER_NAME", principal.getName());
    results = procReadData.execute(in);
    Set<String> keys = results.keySet();
    Iterator<String> iterator = keys.iterator();


    while (iterator.hasNext()) {

        String key = (String) iterator.next();
        personDTOList = (List<PersonDTO>) results.get(key);
    }
    return personDTOList.get(0);
}

数据库配置:

 <Resource driverClassName="oracle.jdbc.OracleDriver" maxActive="300" maxIdle="100" maxWait="5000" name="jdbc/epaws" global="jdbc/epaws" 
        password="polusneu" type="javax.sql.DataSource" url="jdbc:oracle:thin:@192.168.1.60:1521:coeusnew" 
        username="polusneu" validationQuery="select 1 from dual"/> 

applicationcontext.xml配置

<bean id="dbDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
   <property name="jndiName" value="java:comp/env/jdbc/epaws"/>
<property name="resourceRef" value="true"/>
</bean>

0 个答案:

没有答案