javax.servlet.ServletException: Cannot open connection
Bonjour,
Je vous envoie ce message car j'ai un problème de configuration du pool de connexion de Tomcat avec hibernate.
Jusqu'à présent j'ai réussi à me connecter à ma base de données en utilisant le pool de connexion d'hibernate et en définissant directement dans le fichier de conf d'hibernate les données de connexion.
Seulement pour respecter les normes que l'on m'a imposées, je dois exporter ces infos directement dans le fichier de configuration du conteneur de servlets (Tomcat) et utiliser le pool de connexion de ce dernier.
Environnement de développement :
- Base de données Oracle 10 g
- Hibernate 3.1.3
- Tomcat 5.0.28
La structure du projet est la suivante :
Les différents projets utilisés sont générés grâce à maven 2.
gcs-client : c'est la webapp
- src/main/webapp/WEB-INF/web.xml
gcs-dataaccess : couche de données
- src/main/java/ -> contient les sources et les notamment le fichier
hibernate.cfg.xml
gcs-business : couche métier
Ce que j'ai fait jusqu'à présent :
- J'ai commencé par déposer les drivers de connexion à la base de données dans le répertoire /common/lib de Tomcat.
- J'ai modifié ensuite le fichier server.xml de Tomcat :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
<GlobalNamingResources>
...
<Resource name="jdbc/storeDB" auth="Container"
type="javax.sql.DataSource"
username="userQuiVaBien"
password="passwordQuiVaBien"
driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@serveurQuiVaBien:PortQuiVaBien:InstanceDoracleQuiVaBien"
maxActive="8"
maxIdle="4" />
...
</GlobalNamingResources>
...
<Context docBase="gcs-client"
path="/gcs-client"
reloadable="true"
source="org.eclipse.jst.j2ee.server:gcs-client" /> |
- J'ai modifié le fichier hibernate.cfg.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"//psd216/COMPOSANTS-CNP1/hibernate/dtds/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory name="GCS_SessionFactory">
<!-- Utilisation d'une connexion via une DataSource définie au niveau de la conf
du serveur d'application ou conteneur de servlets -->
<property name="connection.datasource">java:/comp/env/jdbc/storeDB</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.OracleDialect</property>
<property name="hibernate.transaction.factory_class">
org.hibernate.transaction.JDBCTransactionFactory
</property>
<!-- Il serait intéressant de définir le mapping dans un fichier externe -->
<mapping resource="GcsCategorieAffaire.hbm.xml" />
<mapping resource="GcsClient.hbm.xml" />
<mapping resource="GcsCodeProduit.hbm.xml" />
<mapping resource="GcsCodeSouscription.hbm.xml" />
<mapping resource="GcsContrat.hbm.xml" />
<mapping resource="GcsEtatAffaire.hbm.xml" />
<mapping resource="GcsInfosComplementaires.hbm.xml" />
<mapping resource="GcsNatureActivite.hbm.xml" />
<mapping resource="GcsNatureLot.hbm.xml" />
<mapping resource="GcsPersonnePhysique.hbm.xml" />
<mapping resource="GcsPosteComptable.hbm.xml" />
<mapping resource="GcsPrioriteLot.hbm.xml" />
<mapping resource="GcsProduit.hbm.xml" />
<mapping resource="GcsReseau.hbm.xml" />
<mapping resource="GcsRole.hbm.xml" />
<mapping resource="GcsRoleIntervenant.hbm.xml" />
<mapping resource="GcsSi.hbm.xml" />
<mapping resource="GcsSiteNumerisation.hbm.xml" />
<mapping resource="GcsTypeAffaire.hbm.xml" />
<mapping resource="GcsTypeArchivage.hbm.xml" />
<mapping resource="GcsTypeDocument.hbm.xml" />
<mapping resource="GcsTypeEvenement.hbm.xml" />
</session-factory>
</hibernate-configuration> |
j'ai ajouté dans le fichier web.xml :
Code:
1 2 3 4 5 6 7
|
<resource-ref>
<description>Connexion à la base de données.</description>
<res-ref-name>jdbc/storeDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref> |
Voila le message qui s'affiche dans la console d'Eclipse :
Code:
1 2 3 4 5
|
INFO fr.cnp.gcs.hibernate.util.HibernateFinder 2008-02-08 09:08:38,066 - find HQL = from GcsContrat fetch all properties where NumeroContrat like '%16303773302%'
WARN org.hibernate.util.JDBCExceptionReporter 2008-02-08 09:08:38,332 - SQL Error: 0, SQLState: null
ERROR org.hibernate.util.JDBCExceptionReporter 2008-02-08 09:08:38,332 - Cannot create JDBC driver of class '' for connect URL 'null'
WARN org.apache.struts.action.RequestProcessor 2008-02-08 09:08:38,332 - Unhandled Exception thrown: class org.hibernate.exception.GenericJDBCException |
Dans la page JSP :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
Etat HTTP 500 -
type Rapport d'exception
message
description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la requête.
exception
javax.servlet.ServletException: Cannot open connection
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
cause mère
org.hibernate.exception.GenericJDBCException: Cannot open connection
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105)
org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
org.hibernate.loader.Loader.doQuery(Loader.java:661)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
org.hibernate.loader.Loader.doList(Loader.java:2145)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
org.hibernate.loader.Loader.list(Loader.java:2024)
org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1106)
org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
fr.cnp.gcs.hibernate.util.HibernateFinder.find(HibernateFinder.java:34)
fr.cnp.gcs.model.business.assure.AssureManager.searchAssureByNumeroContrat(AssureManager.java:106)
fr.cnp.gcs.controller.action.search.SearchAction.execute(SearchAction.java:71)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note La trace complète de la cause mère de cette erreur est disponible dans les fichiers journaux de Apache Tomcat/5.0.28.
Apache Tomcat/5.0.28 |
Si vous pouviez me donner des pistes ca serait pas de refus.
Merci d'avance.
Nono