IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Servlets/JSP Java Discussion :

connection avec un Driver JDBC


Sujet :

Servlets/JSP Java

  1. #1
    Membre habitué
    Inscrit en
    Août 2004
    Messages
    499
    Détails du profil
    Informations forums :
    Inscription : Août 2004
    Messages : 499
    Points : 190
    Points
    190
    Par défaut connection avec un Driver JDBC
    Bonjour,
    j'ai taper un code "servlet" ou je dois me connecter à une base, j'ai donc télécharger le driver mysql "mysql-connector-java-5.0.8" puis je l'ai dézipper.
    ensuite avec eclipse RedHat (J2EE) j'ai été dans Window/Preferences/Connectivity/driver Definition/
    puis dans Mysql 5 j'ai ajouter mon répertoire dézipper auparavant.
    Mais je n'arrive pas à me logger au driver
    j'ai ce message d'erreur

    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
    10 déc. 2007 22:33:40 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
    INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/lib/jvm/java-6-sun-1.6.0.03/jre/lib/i386/client:/usr/lib/jvm/java-6-sun-1.6.0.03/jre/lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.03/jre/../lib/i386:/usr/lib/jvm/java-6-sun-1.6.0.03/jre/lib/i386/client::/usr/lib/jvm/java-6-sun-1.6.0.03/jre/lib/i386::/usr/lib/firefox/:/usr/lib/firefox/:/usr/java/packages/lib/i386:/lib:/usr/lib
    10 déc. 2007 22:33:40 org.apache.coyote.http11.Http11BaseProtocol init
    INFO: Initialisation de Coyote HTTP/1.1 sur http-8080
    10 déc. 2007 22:33:40 org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 1441 ms
    10 déc. 2007 22:33:40 org.apache.catalina.core.StandardService start
    INFO: Démarrage du service Catalina
    10 déc. 2007 22:33:40 org.apache.catalina.core.StandardEngine start
    INFO: Starting Servlet Engine: Apache Tomcat/5.5.25
    10 déc. 2007 22:33:40 org.apache.catalina.core.StandardHost start
    INFO: XML validation disabled
    10 déc. 2007 22:33:41 org.apache.coyote.http11.Http11BaseProtocol start
    INFO: Démarrage de Coyote HTTP/1.1 sur http-8080
    10 déc. 2007 22:33:42 org.apache.jk.common.ChannelSocket init
    INFO: JK: ajp13 listening on /0.0.0.0:8009
    10 déc. 2007 22:33:42 org.apache.jk.server.JkMain start
    INFO: Jk running ID=0 time=0/668  config=null
    10 déc. 2007 22:33:42 org.apache.catalina.storeconfig.StoreLoader load
    INFO: Find registry server-registry.xml at classpath resource
    10 déc. 2007 22:33:42 org.apache.catalina.startup.Catalina start
    INFO: Server startup in 2452 ms
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver10 déc. 2007 22:34:51 org.apache.catalina.core.StandardContext reload
    INFO: Le rechargement de ce contexte a démarré
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver10 déc. 2007 22:39:21 org.apache.catalina.core.StandardContext reload
    INFO: Le rechargement de ce contexte a démarré
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    Sa vient peut-être de mon code ?
    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
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.io.*;
    import java.sql.*;
    //import com.brainysoftware.java.StringUtil;
     
     public class InesertSQL2 extends HttpServlet 
     {
    	 private String prenom ="";
    	 private String nom ="";
    	 private String pseudo ="";
    	 private String pass ="";
    	 private String urlConnection = "jdbc:mysql://localhost:3306/frontal";
    	 private String loginConnection = "root";
    	 private String passConnection = "xav";
     
     
    	 public void init()
    	 {
    		 try {
    			 Class.forName("com.mysql.jdbc.Driver");
    			 System.out.print("Driver JDBC chargé");
    		 }
    		 catch (ClassNotFoundException e) {
    			 System.out.print(e.toString());
    		 }
    	 }
     
    		protected void doGet(HttpServletRequest request, HttpServletResponse response) 
    		throws ServletException, IOException
    		{
    		//sendPageHeader(response);
    		//sendRegistrationForm(request, response, false);
    		//sendPageFooter(response);
    		}
     
    		protected void doPost(HttpServletRequest request, HttpServletResponse response) 
    		throws ServletException, IOException
    		{
    		 //id = request.getParameter(id);
    		 prenom =request.getParameter(prenom);
    		 nom =request.getParameter(nom);
    		 pseudo =request.getParameter(pseudo);
    		 pass =request.getParameter(pass);
     
    		 boolean error = false;
    		 String message = null;
     
    		 try {
    			 Connection cnx = DriverManager.getConnection(urlConnection, loginConnection, passConnection);
    			 System.out.print("Obtenir la connection");
     
    			 Statement etat = cnx.createStatement();
     
    			 String sql = new String ("SELECT pseudo from user where pseudo = '" + pseudo + "'");
    			 ResultSet req = etat.executeQuery(sql);
    			 if(req.next())
    			 {
    				 req.close();
    				 message = "Le nom < "+ pseudo + " > existe déjà !"; 
    			 }
    			 else 
    			 {
    				req.close();
    			 	sql = "insert into user" + prenom + nom + pseudo + pass + "VALUES" +
    			 	 prenom + nom + pseudo + pass ;
    			 	int insertion = etat.executeUpdate(sql);
     
    			 	if(insertion != 0)
    			 		System.out.print("Merci" + pseudo);
    		 	}
    		 // on ferme la requete
    		 etat.close();
    		// on ferme la connection
    		 cnx.close();
     
    		 }
    		 catch(SQLException e)
    		 {
    			 message = "Erreur dans la requette" + e.toString() + error;
    			 error = true;
    		 }
     
    		 if(message != null)
    		 {
    				PrintWriter sortie = response.getWriter();
    				sortie.print("<strong>" + message + "</strong>");
    		 }
    		 if(error != false)
    		 {
    			 message = "Erreur dans la requette" + error;
    			 //sendRegistrationForm();
    		 }
     
    		response.setContentType("text/html");
    		PrintWriter sortie = response.getWriter();
    		sortie.print("<html>");
    		sortie.print("<head>");
    		sortie.print("<title>Tableaux</title>");
    		sortie.print("<style>");
                    sortie.print("");
                    sortie.print("</style>");
    		sortie.print("<link rel='stylesheet' media='screen' href='MonPremierCss.css' />");
    		sortie.print("</head>");
    		sortie.print("<body>");
     
    		sortie.print("<h2>SQL, Tool</h2>");
    		sortie.print("<h5>Please type your SQL statement in the following box</h5>");
    		sortie.print("<form method='post'>");
    		sortie.print("<textarea name='TexteRequete'>sdfg");
     
    		sortie.print("</textarea>");
    		sortie.print("<submit type='text' name='Execute'>");
    		sortie.print("</form>");
     
    		sortie.print("<table>");
    		sortie.print("<th></th><th>Prénom</th><th>nom</th><th>Pseudo</th><th>Pass</th>");
    		sortie.print("<tr>");
    		sortie.print("<td>qsdfghj</td>");
    		sortie.print("</tr>");
    		sortie.print("</table>");
    		sortie.print("</body>");
    	 }
    }
    Merci d'avance

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Octobre 2007
    Messages
    442
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2007
    Messages : 442
    Points : 540
    Points
    540
    Par défaut
    Hello !

    Pour tomcat, il faut que mysql-connector-java-5.0.8 soit localisé (selon le besoin) :

    - Dans $CATALINA_HOME/common/lib (par exemple pour définir connexion via JNDI)

    ou

    - Dans {WebApp}/WEB-INF/lib (propre au contexte Web)

    Même si tu as renseigné le jar dans Window/Preferences/Connectivity/driver Definition, je ne pense pas qu'eclipse aille le recopier automatiquement dans {WebApp}/WEB-INF/lib pour le déploiement.

    La solution : copier mysql-connector-java-5.0.8 dans {WebApp}/WEB-INF/lib.

Discussions similaires

  1. Réponses: 2
    Dernier message: 03/04/2015, 18h54
  2. [débutant] faire un JAR avec les drivers JDBC
    Par korrigann dans le forum Eclipse Java
    Réponses: 6
    Dernier message: 29/11/2006, 16h46
  3. Connection a DB Oracle avec les drivers natif
    Par Psykotik dans le forum Interfaces de programmation
    Réponses: 3
    Dernier message: 07/09/2006, 11h30
  4. Problème de connection avec JDBC !
    Par obon dans le forum JDBC
    Réponses: 14
    Dernier message: 24/08/2006, 16h38
  5. [JDBC][Debutant]pb url connection avec driver thin
    Par remi_phbc dans le forum JDBC
    Réponses: 2
    Dernier message: 02/12/2004, 12h10

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo