org.postgresql.util.PSQLException: La tentative de connexion a échoué

Je suis de la connexion à postgresql base de données à l'aide de java web services (apache axis) avec JDBC connexions pour obtenir les données.Mais tout à coup, dans la plupart des fois j'obtiens une exception de org.postgresql.util.PSQLException: The connection attempt failed. et, à certains moments, il fonctionne très bien. Ici, je suis en utilisant de nombreuses déclarations préparées à l'avance. Mon exemple de code est

Connection connection=null;
try
{
    Class.forName(driver);
    connection = DriverManager.getConnection(url, username, password);
    ps1=connection.prepareStatement("select * from emp");
    rs1=ps1.executeQuery();
    while(rs1.next())
    {            
        ps2=connection.prepareStatement("select * from dept where dept_no="+rs1.getInt("dept_no"));
        rs2=ps2.executeQuery();
        while(rs2.next())
        {
            ................
            ................
        }
    }
}
catch(Exception e)
{
    System.out.println("Exception occurred is"+e.getMessage());            
}
finally
{
    try{if(rs1!=null)rs1.close();}catch(Exception e){ System.out.println("*1closing error--->"+e);}
    try{if(ps1!=null)ps1.close();}catch(Exception e){ System.out.println("**1closing error--->"+e);}
    try{if(rs2!=null)rs2.close();}catch(Exception e){ System.out.println("*2closing error--->"+e);}
    try{if(ps2!=null)ps2.close();}catch(Exception e){ System.out.println("**2closing error--->"+e);}
    try{if(connection!=null)connection.close();}catch(Exception e){ System.out.println("***closing error--->"+e);}
}

trace de la pile à propos de cette exception est

org.postgresql.util.PSQLException: The connection attempt failed.
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:137)
at org.postgresql.core.ConnectionFactory.openConnection(ConnectionFactory.java:66)
at org.postgresql.jdbc2.AbstractJdbc2Connection.<init>(AbstractJdbc2Connection.java:124)
at org.postgresql.jdbc3.AbstractJdbc3Connection.<init>(AbstractJdbc3Connection.java:30)
at org.postgresql.jdbc3.Jdbc3Connection.<init>(Jdbc3Connection.java:24)
at org.postgresql.Driver.makeConnection(Driver.java:386)
at org.postgresql.Driver.connect(Driver.java:260)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at com.codon.service.WareHouseServer.get_picks(WareHouseServer.java:7415)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:135)
at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:104)
at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:73)
at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:259)
at org.postgresql.core.v3.ConnectionFactoryImpl.doAuthentication(ConnectionFactoryImpl.java:254)
at org.postgresql.core.v3.ConnectionFactoryImpl.openConnectionImpl(ConnectionFactoryImpl.java:95)
... 37 more

J'ai vérifié la postgres les journaux et j'ai trouvé les instructions suivantes dans différents cas

1.AVERTISSEMENT: le travailleur a pris trop de temps à démarrer; annulées.

2.ne pourrait rattacher à la mémoire partagée (touche=...., addr=.....): 487.

3.ne pouvait pas recevoir des données de client: Aucune connexion n'a pu être établie car l'ordinateur cible l'a expressément refusé.

4.inattendu EOF sur la connexion du client.

s'il vous plaît aider moi.Merci d'avance

Vous devez montrer que le trace de pile d'exception, depuis l'exception imbriquée(s) qui contient les détails du problème. Étant donné que vous n'êtes pas à l'aide de connexions regroupées je ne vais pas être surpris si vous n'êtes frapper max_connections questions, mais sans le message d'erreur c'est difficile à dire.
Êtes-vous de fermer toutes préparées et de jeux de résultats? Dans un exemple de fermeture de la ps2 et de la rs2 est caché
J'ai mis à jour la question de la trace de la pile sur l'exception et la dernière fois, j'ai oublié de poster le ps2 et rs2 déclarations de clôture.Je l'ai fait dans l'application.
Le serveur PostgreSQL version et le système d'exploitation hôte? Pourrait-il être un serveur Windows, par hasard?
Salut @Sasi Vara Prasad, j'attends le même problème avec les mêmes postgresql journaux. Je suis en utilisant la valeur par défaut hibernate regroupement de connexion. étiez-vous réussi à résoudre ce problème ?

OriginalL'auteur Sasi Vara Prasad | 2013-04-04