我正在使用postgresql,但在从数据库中的表中获取记录时,我已经收到此异常FATAL: sorry, too many clients
。Postgres + JDBC模板太多客户端已经例外
休耕是连接类:
<context:component-scan base-package="com.trinity" />
<context:property-placeholder location="classpath:/jdbc.properties" order="1" ignore-unresolvable="true"/>
<beans:bean id="dataSourcePOSTGRESQL" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<beans:property name="driverClassName" value="${pg_jdbc.driverClassName}" />
<beans:property name="url" value="${pg_jdbc.url}" />
<beans:property name="username" value="${pg_jdbc.username}" />
<beans:property name="password" value="${pg_jdbc.password}" />
</beans:bean>
jdbc.propertis
pg_jdbc.driverClassName=org.postgresql.Driver
pg_jdbc1.url1=jdbc:postgresql://localhost:5433/iotdb
pg_jdbc.username=postgres
[email protected]
DAO类:
public List<Map<String, Object>> getAllDevicesNames(Integer companyId) {
String sql = "select device_configuration_id,device_name,device_id from iot.device_configuration where company_id = ? ";
List<Map<String, Object>> queryForList = jdbcTemplate.queryForList(sql,new Object[]{companyId});
return queryForList;
}
您使用的是连接池吗?你知道你有多少个开放的连接吗? – chrylis
最有可能的是,你没有关闭你的连接,但没有看到你的连接代码(s),我们不能肯定地说。 –
(注意,如果你使用Spring Boot,你可以跳过配置,它甚至会自动为你配置连接池和JDBC模板。) – chrylis