我在过去2天遇到这个问题,我有一个web服务,从本地数据库中提取数据,将其转换为XML发送到另一个使用HttpGet的Web服务,并获得成功或错误的响应并更新我的本地数据库。一段时间后,我开始得到这个错误:
java.sql.SQLException:无法获得连接,因为我们处于最大连接数(20/20)并且没有可用
我已经尝试在我的server.xml和applicationContext中增加maxconnection但是没有任何改变,总是在一段时间后发生这种情况,
这是我的数据源
<!-- Data sources -->
<bean id="dataSourceStore" name="dataSourceStore" class="org.springframework.jndi.JndiObjectFactoryBean" destroy-method="close">
<property name="jndiName">
<value>java:comp/env/jdbc/StoreDS</value>
</property>
<property name="removeAbandoned" value="true"/>
<property name="initialSize" value="250" />
<property name="maxActive" value="350" />
</bean>
我有2个查询数据库的方法,之后我用这个方法关闭
public void close() {
try {
if (!this.getJdbcTemplate().getDataSource().getConnection().isClosed()) {
this.getJdbcTemplate().getDataSource().getConnection().close();
}
} catch (Exception e) {
e.printStackTrace();
// Logger.getLogger(myDAOImpl.class.getName()).log(Level.SEVERE, null, e);
}
}
下面是一个例子
public void updateStatus(Integer id, String name) {
super.getJdbcTemplate().update(
QueryUtil.QueryAtualizaPedido,
name, id);
close();
}
我的server.xml也有maxActive =“250”,我尝试多次更改但错误始终为20/20
The server encountered an internal error () that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>org.hibernate.exception.GenericJDBCException: Cannot open connection org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126) org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114) org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52) org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449) org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74) com.sun.proxy.$Proxy221.prepareStatement(Unknown Source) br.com.fiorde.dao.conexao.connect.PreparedSt(connect.java:54) br.com.fiorde.servlets.webservice.ImportPedidoXML.validaUsuario(ImportPedidoXML.java:137) br.com.fiorde.servlets.webservice.ImportPedidoXML.doPost(ImportPedidoXML.java:93) br.com.fiorde.servlets.webservice.ImportPedidoXML.doGet(ImportPedidoXML.java:80)javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)</pre></p><p><b>root cause</b> <pre>java.sql.SQLException: Couldn't get connection because we are at maximum connection count (20/20) and there are none available org.logicalcobwebs.proxool.Prototyper.quickRefuse(Prototyper.java:309) org.logicalcobwebs.proxool.ConnectionPool.getConnection(ConnectionPool.java:152) org.logicalcobwebs.proxool.ProxoolDriver.connect(ProxoolDriver.java:89) java.sql.DriverManager.getConnection(DriverManager.java:571) java.sql.DriverManager.getConnection(DriverManager.java:233) org.hibernate.connection.ProxoolConnectionProvider.getConnection(ProxoolConnectionProvider.java:75) org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446) org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167) org.hibernate.jdbc.BorrowedConnectionProxy.invoke(BorrowedConnectionProxy.java:74) com.sun.proxy.$Proxy221.prepareStatement(Unknown Source) br.com.fiorde.dao.conexao.connect.PreparedSt(connect.java:54) br.com.fiorde.servlets.webservice.ImportPedidoXML.validaUsuario(ImportPedidoXML.java:137) br.com.fiorde.servlets.webservice.ImportPedidoXML.doPost(ImportPedidoXML.java:93) br.com.fiorde.servlets.webservice.ImportPedidoXML.doGet(ImportPedidoXML.java:80) javax.servlet.http.HttpServlet.service(HttpServlet.java:617) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
答案 0 :(得分:2)
这通常是在您完成使用后无法关闭连接的结果。这称为连接泄漏。
使用完毕后,您是否正在关闭连接?