Httpclient releasing org.hibernate.Exception.Genericjdbcexception exception exception?

Asked

Viewed 829 times

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

  • 2

    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.

  • 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.

  • That can’t be possible, after all the connections with the bank I do a close up

  • 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?

  • 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.

2 answers

0


Problem solved, it was a Session error caused by the client and not by the server.

  • None of them Were helpful.

  • If you’ve found the solution for yourself, post it and mark it as accepted. Write as if you were giving an answer to a question that was not yours, tendeu?

  • That’s what I did.

-1

The problem is described in the exception, the maximum number of connections with the bank (20) was exceeded. You can configure the database and increase this number or use a kind of connection pool, where the system keeps an X number of connections open and uses the same connections for different queries. There are numerous possibilities.

  • I think that fits more as a comment, no?

  • @Pauloroberto As I will comment with 1 point of reputation?

  • In addition, it reads the question: 'Is there any reason for the following code to release this exception? Yes, there is, and the reason was pointed out in my reply.

  • But you should not act like that. If you have a comment, and you cannot comment, you should not simply post as a response. Reputation is easy to achieve here at Stackoverflow, and you can also wait for the question to develop through the comments conversations and then post a concrete answer :) we are in no hurry here.

  • Yeah, tell me then an easy way to get a reputation if you don’t answer the questions, because as far as I’m concerned, this is how you get a reputation. :)

  • There are some ways to get a reputation. You can earn reputation by editing answers and questions, for example, and if your issues are approved, you gain +2 reputation for each approved issue. And also by asking a question you can earn +5 of reputation each time you give a positive vote to your question.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.