Mauro M
Mauro M

Reputation: 669

JDBC Maximum connection

i am stuck on this problem for the past 2 days, i have a webservice that extract Data from a local database converts it to XML sends to another webservice with HttpGet and gets the response of success or faile and updates my local database. After some time i start to get this Error:

java.sql.SQLException: Couldn't get connection because we are at maximum connection count (20/20) and there are none available

I have tried increasing the maxconnection in my server.xml and applicationContext but nothing changes, always after some time this happens,

This is my datasource

<!-- 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>

I have 2 methods that queries de Database, after them i use this one to close

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

Heres one example

public void updateStatus(Integer id, String name) {
    super.getJdbcTemplate().update(
            QueryUtil.QueryAtualizaPedido, 
            name, id);
    close();

}

My server.xml also has maxActive="250", i tried to change this several times but the error always comes as 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)

Upvotes: 0

Views: 4979

Answers (1)

matt b
matt b

Reputation: 140041

This usually is a result of failing to close connections when you are done using them. This is known as a connection leak.

Are you closing connections when you are done using them?

Upvotes: 2

Related Questions