Probleme connexion base de donnée(JEE)

Résolu
couranes Messages postés 17 Date d'inscription lundi 6 décembre 2010 Statut Membre Dernière intervention 17 avril 2012 - 8 juil. 2011 à 17:04
couranes Messages postés 17 Date d'inscription lundi 6 décembre 2010 Statut Membre Dernière intervention 17 avril 2012 - 8 juil. 2011 à 23:12
bonjour tout le monde,j'essaye depuis un moment de se connecté à une base de donnée et d'afficher les noms qui existent dans une table mais il m'affiche toujours des erreurs.j'utilise comme language de programmation Java EE.et voila mon code :
****************************************
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
************************************************** ****
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
try
{
Class.forName("com.mysql.jdbc.Driver");
java.sql.Connection ma_connection = DriverManager.getConnection("jdbc:mysql://localhost:8080/test","admin","");
Statement mon_statement = ma_connection.createStatement();
ResultSet mon_resultat = mon_statement.executeQuery("SELECT * FROM etd");
while(mon_resultat.next())
{
out.println("les noms sont : "+mon_resultat.getString("nom"));
**

**catch(SQLException e)
{

** catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
**
**

6 réponses

cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
8 juil. 2011 à 21:47
ClassNotFoundException : tu as un problème avec ton classPath : tu as ajouté la librairie jdbc ?

Attention, cette librairie est utile sur le serveur, il ne faut donc pas la mettre dans le dossier lib de webContent mais bien dans le classPath.
3
hindou23 Messages postés 42 Date d'inscription lundi 7 septembre 2009 Statut Membre Dernière intervention 20 octobre 2011
8 juil. 2011 à 17:07
Pourquoi tu as laissé le champ du nom de la table vide ??? ""

Normalement tu dois spécifier meme le nom pour qu'il cherche la dedans!!!
0
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
8 juil. 2011 à 18:03
Peux tu nous donner la trace de l'errer s'il te plais ?
0
cs_Julien39 Messages postés 6414 Date d'inscription mardi 8 mars 2005 Statut Modérateur Dernière intervention 29 juillet 2020 371
8 juil. 2011 à 18:04
@hindou23 : je ne vois pas ou le champ de la table est vide, tout me semble correct.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
couranes Messages postés 17 Date d'inscription lundi 6 décembre 2010 Statut Membre Dernière intervention 17 avril 2012
8 juil. 2011 à 19:49
voila le message d'erreur :
*************************************
8 juil. 2011 18:35:58 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/Java/jre6/bin/client;C:/Program Files/Java/jre6/bin;C:/Program Files/Java/jre6/lib/i386;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files\AMD APP\bin\x86;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Windows Live\Shared;C:\Windows\system32\gs\gs7.05\bin;C:\eclipse;;.
8 juil. 2011 18:35:58 org.apache.tomcat.util.digester.SetPropertiesRule begin
ATTENTION: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:toto' did not find a matching property.
8 juil. 2011 18:35:58 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8080"]
8 juil. 2011 18:35:58 org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
8 juil. 2011 18:35:58 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 473 ms
8 juil. 2011 18:35:58 org.apache.catalina.core.StandardService startInternal
INFO: Démarrage du service Catalina
8 juil. 2011 18:35:58 org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.16
8 juil. 2011 18:35:58 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
8 juil. 2011 18:35:58 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
8 juil. 2011 18:35:58 org.apache.catalina.startup.Catalina start
INFO: Server startup in 362 ms
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at Connection.doGet(Connection.java:40)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
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:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
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:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:403)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:301)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:162)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:140)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
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)
0
couranes Messages postés 17 Date d'inscription lundi 6 décembre 2010 Statut Membre Dernière intervention 17 avril 2012
8 juil. 2011 à 23:12
merci bien pour votre aide.Maintenant ca marche à merveille
0
Rejoignez-nous