-3
Is there any reason for the following code to release this exception? I have one webservice
who consults at my bank and turns everything into xml and then make a send to another webservice
takes the reply and updates my bank, everything works fine until the code runs exactly 20 times, then I get a this exception:
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.store.dao.conexao.connect.PreparedSt(connect.java:54) br.com.store.servlets.webservice.ImportPedidoXML.validaUsuario(ImportPedidoXML.java:137) br.com.store.servlets.webservice.ImportPedidoXML.doPost(ImportPedidoXML.java:93) br.com.store.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)
root cause
java.sql.SQLException: Couldn't get connection because we are at maximum connection count (20/20) and there are none available
Follow the code that connects to the client:
try {
HttpClient client = new DefaultHttpClient();
URIBuilder builder = new URIBuilder();
builder.setScheme("http")
.setHost(StoreWS.getHostStatus())
.setPath(StoreWS.getPathStatus())
.setParameter("tx_login", StoreWS.getUsuarioStatus())
.setParameter("tx_senha", StoreWS.getSenhaStatus())
.setParameter("cd_pedido",
String.valueOf(pedido.getCd_pedido()));
URI url = builder.build();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String output;
while ((output = br.readLine()) != null) {
resposta.append(output);
}
br.close();
response.getEntity().getContent().close();
// client.getConnectionManager().shutdown();
} catch (Exception e) {
e.printStackTrace();
} finally {
return resposta.toString();
}
The exception always appears here, it does not appear when I update my bank after receiving the response which would make more sense to be an exception of JDBC
?
Use Spring
, JDBCTemplate
with DataSource
, I’ve tried everything, increase the pool, but always gives the same problem.
Probably you are connecting again (to each request) in a part of the pool of connections that is as limit of 20 connections, so when trying for the 21st time will take. You should treat this exception as "exceeded simultaneous connection limit" or use the same transaction to perform all queries, or close the connection whenever the query ends.
– Paulo Roberto Rosa
You’re opening 20 connections (maximum) and you’re not closing when you’re done. Then all the connections are open and he can’t open a new one. The solution of @Pauloroberto seems to be ideal.
– Felipe Avelar
That can’t be possible, after all the connections with the bank I do a close up
– Mauro M
What the error accuses is exactly what is being said. It could show where you make the connection in the database to save the data?
– Felipe Avelar
Honestly, question and answer are a typical case of XY problem. While I see the author’s effort to answer his own question as something commendable, I think the whole presented here is of little value to the community at large.
– Anthony Accioly