Spring JDBC模板使用调用过程时创建的新数据库用户实例
我使用Spring Mvc Jdbc模板调用过程和函数。但是函数调用后数据库连接没有关闭。每次创建新的数据库用户实例。有人能给我解决这个大问题的解决方案吗Spring JDBC模板使用调用过程时创建的新数据库用户实例,spring,jdbctemplate,Spring,Jdbctemplate,我使用Spring Mvc Jdbc模板调用过程和函数。但是函数调用后数据库连接没有关闭。每次创建新的数据库用户实例。有人能给我解决这个大问题的解决方案吗 @Autowired @Qualifier("dbDataSource") public DataSource dataSource; public SimpleJdbcCall procReadData; public PersonDTO readPersonData(Principal principal) throws SQLExcep
@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);
}
@Autowired
@限定符(“dbDataSource”)
公共数据源;
公共SimpleJdbcCall procReadData;
public PersonDTO readPersonData(主体)引发SQLException{
List personDTOList=null;
映射结果=空;
procReadData=新的SimpleJDBCall(数据源)。使用PROCEDURENAME(“GET_PAWS_PERSON_DETAILS”);
addDeclaredParameter(新的SqlParameter(“AV_USER_NAME”,OracleTypes.VARCHAR));
procReadData.addDeclaredParameter(新的SqlOutParameter(“CUR_GENERIC”,OracleTypes.CURSOR,new PersonRowMapper());
SqlParameterSource in=new-MapSqlParameterSource().addValue(“AV_USER_NAME”,principal.getName());
结果=procReadData.execute(in);
Set keys=results.keySet();
迭代器迭代器=keys.Iterator();
while(iterator.hasNext()){
字符串键=(字符串)迭代器。下一步();
personDTOList=(List)results.get(key);
}
返回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>
请添加一些配置,code..。@M.Deinum添加了代码。请查看并发布您的配置。从代码中注意到的一点是,您似乎没有正确的tx管理设置。我在tomcat server.xml中添加了数据库配置,在applicationcontext.xml中添加了datasource congiguretion。请不要将代码作为注释添加,用它改进您的问题。另外,如何检查连接是否未关闭?