2015-04-07 1 views
0

J'ai créé un pool de connexions JDBC dans Glassfish et l'utilise comme ressource JDBC "jdbc/__ default". Je peux exécuter une commande ping sur ce pool de connexions avec succès dans l'interface de la console d'administration.Erreur de connexion JDBC

Alors, je suis en train d'exécuter le programme suivant:

package de.java2enterprise.onlineshop; 

import java.io.FileWriter; 
import java.io.IOException; 
import java.io.PrintWriter; 
import java.sql.Connection; 

import javax.annotation.Resource; 
import javax.naming.InitialContext; 
import javax.servlet.ServletException; 
import javax.servlet.annotation.WebServlet; 
import javax.servlet.http.HttpServlet; 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
import javax.sql.DataSource; 

@WebServlet("/test") 
public class TestServlet extends HttpServlet { 
    private static final long serialVersionUID = 1L; 

    // @Resource(name="jdbc/__default") 
    // private DataSource ds; 

    public void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 

     PrintWriter writer = response.getWriter(); 
     response.setContentType("text/html;charset=UTF-8"); 
     writer.println("<!DOCTYPE html>"); 
     writer.println("<html><body>"); 

     Connection con = null; 
     DataSource ds; 
     try { 

      ds = (DataSource) InitialContext.doLookup("jdbc/__default"); 
      con = ds.getConnection(); 

      if (con.isValid(10)) { 
       writer.println("<BR>Connected!"); 
      } 
      con.close(); 

     } catch (Exception ex) { 
      writer.println(ex.getMessage()); 
     } finally { 
      if (con != null){ 
       try{ 
        con.close(); 
       } catch (Exception ex){ 

       } 
      } 
     } 
     writer.println("<BR>Test finished!</body></html>"); 
     writer.close(); 
    } 
} 

Cependant, je reçois l'erreur suivante dans le navigateur Web:

Error in allocating a connection. Cause: Connection could not be allocated because: Listener refused the connection with the following error: ORA-12518, TNS:listener could not hand off client connection Test finished!

Dans le journal du serveur, je reçois le erreur suivante:

2015-04-08T08:15:20.540+0200|Information: Loading application [onlineshop#onlineshop-war.war] at [onlineshop-war] 2015-04-08T08:15:20.636+0200|Information: onlineshop was successfully deployed in 611 milliseconds. 2015-04-08T08:15:38.552+0200|Warnung: Context path from ServletContext: /onlineshop-war differs from path from bundle: onlineshop-war 2015-04-08T08:15:38.802+0200|Information: visiting unvisited references 2015-04-08T08:15:39.519+0200|Information: Successfully got INSTRUMENTATION: [email protected]

2015-04-08T08:15:41.471+0200|Warnung: RAR5038:Unexpected exception while creating resource for pool Onlineshop. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: Listener refused the connection with the following error: ORA-12516, TNS:listener could not find available handler with matching protocol stack

2015-04-08T08:15:41.471+0200|Warnung: RAR5117 : Failed to obtain/create connection from connection pool [ Onlineshop ]. Reason : com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: Listener refused the connection with the following error: ORA-12516, TNS:listener could not find available handler with matching protocol stack

2015-04-08T08:15:41.486+0200|Warnung: RAR5114 : Error allocating connection : [Error in allocating a connection. Cause: Connection could not be allocated because: Listener refused the connection with the following error: ORA-12516, TNS:listener could not find available handler with matching protocol stack ]

Après cela, je ne peux plus exécuter de ping sur le pool de connexions et recevoir plus ou moins la même erreur dans la console d'administration.

J'utilise la configuration suivante: JDK 1.8.0_25, Open Source Edition 4.1 de GlassFish Server (version 13), Oracle Database XE 11.2.

Dans la console d'administration Glassfish, j'ai créé la ressource JDBC suivante: JNDI Nom: jdbc/__ défaut, Nom JNDI logique: java: comp/DefaultDatasource, Piscine Connection: en ligne. Le nom du pool de connexions JDBC est Onlineshop, Type de ressource: javax.sql.DataSource, Nom de la classe: oracle.jdbc.pool.OracleDataSource. J'ai une taille de pool minimale de 800 connexions, maximum de 3200 connexions.

Les autres paramètres que j'ai conservés tels qu'ils étaient, j'ai seulement ajouté l'utilisateur et le mot de passe dans les propriétés du pool de connexions JDBC.

Quelqu'un a une idée? :-)

Répondre

1

Fermez votre connexion dans un finally block ou dans try-with-resources si vous utilisez jdk7 + comme cela devrait être fait en Java. Voir si cela aide

+0

Salut jjd, merci! J'ai ajouté ce qui suit à mon code, mais cela ne fonctionne pas: 'finally { \t \t \t if (! Con = null) { \t \t \t \t try { \t \t \t \t \t con.close () \t \t \t \t \t writer.close(); \t \t \t \t} catch (Exception ex) { \t \t \t \t \t \t \t \t \t} \t \t \t} \t \t} ' – mike128

+0

Pouvez-vous, pls, mettez à jour le code avec les modifications apportées, aussi fournir plus d'informations comme ce DB que vous utilisez, quel pilote, les paramètres du pool de connexion – jjd

+0

J'ai ajouté des informations ci-dessus. Quelque chose manque encore? – mike128