Bonjour à tous,
Avant tous je tiens à m'excuser si je ne poste pas au bonne endroit. En effet je ne sais pas si cela est un problème tomcat ou purement du projet JSP.
Je vous explique mon problème.
J'ai un document .properties qui contiens les données pour la connection à la base sql ensuite j'ai une classe IoData qui contiens des méthodes pour charger ce dit properties et lis les données qu'elle retourne.
Après j'ai une classe utilisant un singleton qui appelle une interface qui appel IoData qui donc elle se charge de charger puis lire puis retrounée les données.
j'ai créer une classe de teste pour vérifier que cela fonctionne tout est OK.
Attention quand je dit OK c'est une classe de test lancé en console.
Par contre une fois que je lance mon index.jsp qui lui est un formulaire et qui demande une connection à la db, alors j'ai un message d'erreur comme quoi il ne sais pas lire le fichier (le trouve pas).
Cela fait 3 jour que je cherche le problème et je ne trouve vraiment pas, j'ai essayer plusieurs forum il parle de problème de lecture mais pas de problème comme le miens
on dirais que le chemin n'est pas connus une fois qu'il passe par le WebContent.
j'espère que vous pourrez m'aider
voici le code des classe et le message d'erreur
TomCat 7 / Eclipse Helios / JRE6
IoData.java
Constant.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138 package be.festiwavre.dao.rl.connection; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Properties; import org.apache.log4j.Logger; import be.festiwavre.dao.rl.connection.Constant; import be.festiwavre.dao.rl.connection.DbConnection; import be.festiwavre.dao.rl.connection.DbConnection; import be.festiwavre.rl.io.IoData; /** * Classe de gestion et de connexion à la db * @author Rudy Lemaitre * */ public class DbConnection { /** * URL de connection */ private String url; /** * Nom du user */ private String user; /** * Mot de passe du user */ private String passwd; /** * Objet connection */ private static Connection connect; /** * mise en service du logger */ private static final Logger log = Logger.getLogger(DbConnection.class); /** * Méthode qui charge les données d'un fichier properties et qui garnis les variables de * connection pour la db * @author Rudy Lemaitre */ private void processProperties() { Properties properties = new Properties(); IoData loadDataDb = new IoData(); try { properties = loadDataDb.ConnectionParameter(Constant.FICHIER_CONFIG); } catch (Exception e) { log.fatal("Impossible de charger le fichier de config : vérifier la classe Constant et le chemin d'accès"); } this.user = ((String) properties.getProperty("usr")); this.passwd = ((String) properties.getProperty("passwd")); this.url = ((String) properties.getProperty("url")); } /** * Méthode qui se charge d'établir la connection à la Db * @author Rudy Lemaitre */ private DbConnection(){ try { processProperties(); connect = DriverManager.getConnection(url, user, passwd); log.debug("Connection à la db OK !"); } catch (SQLException e) { log.fatal("Connection à la db échouée "+url+" "+user+" "+passwd); } } /** * Méthode qui va nous retourner notre instance de connection * et la créer si elle n'existe pas * @return instance de la connection * @author Rudy Lemaitre */ public static Connection getInstance(){ if(connect == null){ log.debug("Initialisation d'une nouvelle connexion ..."); new DbConnection(); } else { log.debug("Connection à la db déjà établie"); } return connect; } /** * Méthode qui va permettre de fermer la connection à la db * @throws SQLException * @author Rudy Lemaitre */ public static void closeConnection() throws SQLException{ if(connect == null){ log.debug("Connection déjà fermée"); } else { log.debug("Fermeture de la connexion à la Db en cour ..."); connect.close(); log.debug("Connection fermée"); } } /** * Méthode qui se charge de fermer un resultset et un callableStatement * @param rs : attend le nom d'un resultset * @param CallStmt : attend le nom d'un callableStatement * @author Rudy Lemaitre */ public static void closeAll(ResultSet rs, CallableStatement callStmt) { if (rs != null) { try { log.debug("Fermeture du ResultSet en cour ..."); rs.close(); log.debug("ResultSet fermer"); } catch (SQLException e) { log.debug("Fermeture du ResultSet impossible"); } } if (callStmt != null) { try { log.debug("Fermeture du CallableStatement en cour ..."); callStmt.close(); log.debug("CallableStatement fermer"); } catch (SQLException e) { log.debug("Fermeture du PreparedStatement impossible"); } } } }
DbConnection.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 package be.festiwavre.dao.rl.connection; /** * <p> * Interface pour la récupération d'un fichier de configuration à la Db * <p> * @author Rudy Lemaitre */ public interface Constant { /** connection et récupération des donnée des différents properties */ public static final String FICHIER_CONFIG=".//config//dbParametre.properties"; }
dbParametre.properties
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138 package be.festiwavre.dao.rl.connection; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Properties; import org.apache.log4j.Logger; import be.festiwavre.dao.rl.connection.Constant; import be.festiwavre.dao.rl.connection.DbConnection; import be.festiwavre.dao.rl.connection.DbConnection; import be.festiwavre.rl.io.IoData; /** * Classe de gestion et de connexion à la db * @author Rudy Lemaitre * */ public class DbConnection { /** * URL de connection */ private String url; /** * Nom du user */ private String user; /** * Mot de passe du user */ private String passwd; /** * Objet connection */ private static Connection connect; /** * mise en service du logger */ private static final Logger log = Logger.getLogger(DbConnection.class); /** * Méthode qui charge les données d'un fichier properties et qui garnis les variables de * connection pour la db * @author Rudy Lemaitre */ private void processProperties() { Properties properties = new Properties(); IoData loadDataDb = new IoData(); try { properties = loadDataDb.ConnectionParameter(Constant.FICHIER_CONFIG); } catch (Exception e) { log.fatal("Impossible de charger le fichier de config : vérifier la classe Constant et le chemin d'accès"); } this.user = ((String) properties.getProperty("usr")); this.passwd = ((String) properties.getProperty("passwd")); this.url = ((String) properties.getProperty("url")); } /** * Méthode qui se charge d'établir la connection à la Db * @author Rudy Lemaitre */ private DbConnection(){ try { processProperties(); connect = DriverManager.getConnection(url, user, passwd); log.debug("Connection à la db OK !"); } catch (SQLException e) { log.fatal("Connection à la db échouée "+url+" "+user+" "+passwd); } } /** * Méthode qui va nous retourner notre instance de connection * et la créer si elle n'existe pas * @return instance de la connection * @author Rudy Lemaitre */ public static Connection getInstance(){ if(connect == null){ log.debug("Initialisation d'une nouvelle connexion ..."); new DbConnection(); } else { log.debug("Connection à la db déjà établie"); } return connect; } /** * Méthode qui va permettre de fermer la connection à la db * @throws SQLException * @author Rudy Lemaitre */ public static void closeConnection() throws SQLException{ if(connect == null){ log.debug("Connection déjà fermée"); } else { log.debug("Fermeture de la connexion à la Db en cour ..."); connect.close(); log.debug("Connection fermée"); } } /** * Méthode qui se charge de fermer un resultset et un callableStatement * @param rs : attend le nom d'un resultset * @param CallStmt : attend le nom d'un callableStatement * @author Rudy Lemaitre */ public static void closeAll(ResultSet rs, CallableStatement callStmt) { if (rs != null) { try { log.debug("Fermeture du ResultSet en cour ..."); rs.close(); log.debug("ResultSet fermer"); } catch (SQLException e) { log.debug("Fermeture du ResultSet impossible"); } } if (callStmt != null) { try { log.debug("Fermeture du CallableStatement en cour ..."); callStmt.close(); log.debug("CallableStatement fermer"); } catch (SQLException e) { log.debug("Fermeture du PreparedStatement impossible"); } } } }
MESSAGE TOMCAT
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4#Parametres de connection à la db usr=user passwd=user url=jdbc:mysql://xxxxxx:3306/festi
Architecture du dossier :03-mars-2011 11:41:15 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files (x86)\PC Connectivity Solution\;C:\Program Files (x86)\ActiveState Komodo Edit 5\;c:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\Acronis\SnapAPI\;C:\Program Files\MySQL\MySQL Server 5.1\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files (x86)\Belgium Identity Card;C:\Program Files (x86)\Druide\Antidote 7\Programmes32;C:\Program Files (x86)\Druide\Antidote 7\Programmes64;C:\Program Files (x86)\QuickTime\QTSystem\
03-mars-2011 11:41:15 org.apache.tomcat.util.digester.SetPropertiesRule begin
ATTENTION: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:FestiWavre' did not find a matching property.
03-mars-2011 11:41:15 org.apache.tomcat.util.digester.SetPropertiesRule begin
ATTENTION: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.j2ee.serveraperLandReviewed' did not find a matching property.
03-mars-2011 11:41:15 org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
03-mars-2011 11:41:15 org.apache.coyote.AbstractProtocolHandler init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
03-mars-2011 11:41:15 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 459 ms
03-mars-2011 11:41:15 org.apache.catalina.core.StandardService startInternal
INFO: Démarrage du service Catalina
03-mars-2011 11:41:15 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.8
03-mars-2011 11:41:16 org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["http-bio-8080"]
03-mars-2011 11:41:16 org.apache.coyote.AbstractProtocolHandler start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
03-mars-2011 11:41:16 org.apache.catalina.startup.Catalina start
INFO: Server startup in 669 ms
2011-03-03 11:41:21 DEBUG [DbConnection] Initialisation d'une nouvelle connexion ...
java.io.FileNotFoundException: .\config\dbParametre.properties (Le chemin d’accès spécifié est introuvable)
2011-03-03 11:41:21 FATAL [DbConnection] Erreur de chargement - fichier de connection à la DB introuvable
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at be.festiwavre.rl.io.IoData.ConnectionParameter(IoData.java:42)
at be.festiwavre.dao.rl.connection.DbConnection.processProperties(DbConnection.java:59)
at be.festiwavre.dao.rl.connection.DbConnection.<init>(DbConnection.java:74)
at be.festiwavre.dao.rl.connection.DbConnection.getInstance(DbConnection.java:90)
at be.festiwavre.dao.rl.checkUsers.CheckUserDAOMySqlImpl.checkForUserConnect(CheckUserDAOMySqlImpl.java:52)
at be.festiwavre.rl.servlets.UserControl.doPost(UserControl.java:94)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:306)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:383)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:243)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:288)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
2011-03-03 11:41:21 FATAL [DbConnection] Impossible de charger le fichier de config : vérifier la classe Constant et le chemin d'accès
2011-03-03 11:41:21 FATAL [DbConnection] Connection à la db échouée null null null
2011-03-03 11:41:21 DEBUG [CheckUserDAOMySqlImpl] Procédure Rl_CheckUserForLogin non exécutée
java.lang.NullPointerException
2011-03-03 11:41:21 DEBUG [UserControl] Recherche de l'utilisateur en db terminée : information récupérée
2011-03-03 11:41:21 ERROR [UserControl] L'utilisateur vbg n'existe pas en base de données
Encore un grand merci à tous ...
Rudy
Partager