Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1153 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Aide : Connexion J2EE / Mysql

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Aide : Connexion J2EE / Mysql

n°1532246
Sinan
Posté le 22-03-2007 à 15:52:28  profilanswer
 

Bonjour,
 
Nous avons un probleme pour le développement d'une application web.
 
La config est :
Tomcat 6.0.10
Mysql 5.0.37
mysql-connector-java-5.0.5
 
Nous avons tout installé, la base de donnée tourne correctement et nous permet de lancer des requetes sans soucis.
Le tomcat marche aussi nickel.
 
Le MySql connector est présent dans le C:\Program Files\Apache\Tomcat\lib
 
Voici nos parametres xml :
 
server.xml :
 

Code :
  1. <!-- Note:  A "Server" is not itself a "Container", so you may not
  2.      define subcomponents such as "Valves" at this level.
  3.      Documentation at /docs/config/server.html
  4. -->
  5. <Server port="8005" shutdown="SHUTDOWN">
  6.   <!--APR library loader. Documentation at /docs/apr.html -->
  7.   <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
  8.   <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
  9.   <Listener className="org.apache.catalina.core.JasperListener" />
  10.   <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
  11.   <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
  12.   <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
  13.   <!-- Global JNDI resources
  14.        Documentation at /docs/jndi-resources-howto.html
  15.   -->
  16.   <GlobalNamingResources>
  17.     <!-- Editable user database that can also be used by
  18.          UserDatabaseRealm to authenticate users
  19.     -->
  20.     <Resource name="UserDatabase" auth="Container"
  21.               type="org.apache.catalina.UserDatabase"
  22.               description="User database that can be updated and saved"
  23.               factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
  24.               pathname="conf/tomcat-users.xml" />
  25.   </GlobalNamingResources>
  26.   <!-- A "Service" is a collection of one or more "Connectors" that share
  27.        a single "Container" Note:  A "Service" is not itself a "Container",
  28.        so you may not define subcomponents such as "Valves" at this level.
  29.        Documentation at /docs/config/service.html
  30.    -->
  31.   <Service name="Catalina">
  32.     <!-- A "Connector" represents an endpoint by which requests are received
  33.          and responses are returned. Documentation at :
  34.          Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
  35.          Java AJP  Connector: /docs/config/ajp.html
  36.          APR (HTTP/AJP) Connector: /docs/apr.html
  37.          Define a non-SSL HTTP/1.1 Connector on port 8080
  38.     -->
  39.     <Connector port="8080" protocol="HTTP/1.1"
  40.                maxThreads="150" connectionTimeout="20000"
  41.                redirectPort="8443" />
  42.     <!-- Define a SSL HTTP/1.1 Connector on port 8443
  43.          This connector uses the JSSE configuration, when using APR, the
  44.          connector should be using the OpenSSL style configuration
  45.          described in the APR documentation -->
  46.     <!--
  47.     <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
  48.                maxThreads="150" scheme="https" secure="true"
  49.                clientAuth="false" sslProtocol="TLS" />
  50.     -->
  51.     <!-- Define an AJP 1.3 Connector on port 8009 -->
  52.     <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
  53.     <!-- An Engine represents the entry point (within Catalina) that processes
  54.          every request.  The Engine implementation for Tomcat stand alone
  55.          analyzes the HTTP headers included with the request, and passes them
  56.          on to the appropriate Host (virtual host).
  57.          Documentation at /docs/config/engine.html -->
  58.     <!-- You should set jvmRoute to support load-balancing via AJP ie :
  59.     <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">       
  60.     -->
  61.     <Engine name="Catalina" defaultHost="localhost">
  62.       <!--For clustering, please take a look at documentation at:
  63.           /docs/cluster-howto.html  (simple how to)
  64.           /docs/config/cluster.html (reference documentation) -->
  65.       <!--
  66.       <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
  67.       -->       
  68.       <!-- The request dumper valve dumps useful debugging information about
  69.            the request and response data received and sent by Tomcat.
  70.            Documentation at: /docs/config/valve.html -->
  71.       <!--
  72.       <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
  73.       -->
  74.       <!-- This Realm uses the UserDatabase configured in the global JNDI
  75.            resources under the key "UserDatabase".  Any edits
  76.            that are performed against this UserDatabase are immediately
  77.            available for use by the Realm.  -->
  78.       <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
  79.              resourceName="UserDatabase"/>
  80.       <!-- Define the default virtual host
  81.            Note: XML Schema validation will not work with Xerces 2.2.
  82.        -->
  83.       <Host name="localhost"  appBase="webapps"
  84.             unpackWARs="true" autoDeploy="true"
  85.             xmlValidation="false" xmlNamespaceAware="false">
  86.         <!-- SingleSignOn valve, share authentication between web applications
  87.              Documentation at: /docs/config/valve.html -->
  88.         <!--
  89.         <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
  90.         -->
  91.         <!-- Access log processes all example.
  92.              Documentation at: /docs/config/valve.html -->
  93.         <!--
  94.         <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
  95.                prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
  96.         -->
  97. <Context path="/TutoPool"
  98. reloadable="true"
  99. docBase="\TutoPool" >
  100. <Resource
  101.  name="jdbc/TutoPool"
  102.  auth="Container"
  103.  type="javax.sql.DataSource"/>
  104. <ResourceParams name="jdbc/TutoPool">
  105.  <parameter>
  106.   <name>username</name>
  107.   <value>root</value>
  108.   </parameter>
  109.  <parameter>
  110.   <name>password</name>
  111.   <value>admin</value>
  112.  </parameter>
  113.   <parameter>
  114.   <name>driverClassName</name>
  115.   <value>org.gjt.mm.mysql.Driver</value>
  116.   </parameter>
  117.  <parameter>
  118.   <name>url</name>
  119.   <value>jdbc:mysql://localhost:3306/javatest</value>
  120.  </parameter>
  121. </ResourceParams>
  122. </Context>
  123.       </Host>
  124.     </Engine>
  125.   </Service>
  126. </Server>


 
Nous avons ensuite crée un projet java avec la bonne structure.
 
Voici le web.xml
 

Code :
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">  
  3. <web-app>
  4. <display-name>TutoPool</display-name>
  5. <servlet>
  6.  <servlet-name>TutoPool</servlet-name>
  7.  <servlet-class>tutorial.TutoPool</servlet-class>
  8. </servlet>
  9. <servlet-mapping>
  10.  <servlet-name>TutoPool</servlet-name>
  11.  <url-pattern>/</url-pattern>
  12. </servlet-mapping>
  13. <resource-ref>
  14.  <description>
  15.   reference a la ressource BDD pour le pool
  16.  </description>
  17.  <res-ref-name>jdbc/TutoPool</res-ref-name>
  18.  <res-type>javax.sql.DataSource</res-type>
  19.  <res-auth>Container</res-auth>
  20. </resource-ref>
  21. </web-app>


 
Voici la classe qui tente de faire une requete :
 

Code :
  1. import java.io.*;
  2. import java.sql.*;
  3. import javax.naming.*;
  4. import javax.servlet.*;
  5. import javax.servlet.http.*;
  6. import javax.sql.*;
  7. public class TutoPool extends HttpServlet {
  8. private DataSource ds; //la source de données
  9. protected void doGet(
  10.  HttpServletRequest request,
  11.  HttpServletResponse response)
  12.  throws ServletException, IOException {
  13.  response.setContentType("text/html" );
  14.  PrintWriter out = response.getWriter();
  15.  out.println("<html><head></head>" );
  16.  out.println("<body>" );
  17.  Connection con = null;
  18.  Statement s = null;
  19.  ResultSet rs = null;
  20.  try {
  21.   //récupération de la Connection depuis le DataSource
  22.   con = ds.getConnection();
  23.   s = con.createStatement();
  24.   rs = s.executeQuery("SELECT * FROM javatest.testdata t;" );
  25.   while (rs.next()) {
  26.    out.println("Test :<br/>" );
  27.    out.println(rs.getString(1) + "      " );
  28.    out.println(rs.getString(2) + "<br/>" );
  29.   }
  30.  } catch (SQLException e) {
  31.   response.sendError(500, "TA MERE LA PUTE " + e);
  32.  } finally {
  33.   if (rs != null)
  34.   {
  35.    try {
  36.     rs.close();
  37.    } catch (SQLException e) {}
  38.    rs = null;
  39.   }
  40.   if (s != null) {
  41.    try {
  42.     s.close();
  43.    } catch (SQLException e) {}
  44.    s = null;
  45.   }
  46.   if (con != null) {
  47.    try {
  48.     con.close();
  49.    } catch (SQLException e) {}
  50.    con = null;
  51.   }
  52.  }
  53.  out.println("</body>" );
  54.  out.println("</html>" );
  55.  out.close();
  56. }
  57. public void init() throws ServletException {
  58.  try {
  59.   //récupération de la source de donnée
  60.   Context initCtx = new InitialContext();
  61.   ds = (DataSource) initCtx.lookup("java:comp/env/jdbc/TutoPool" );
  62.  } catch (Exception e) {
  63.   throw new UnavailableException(e.getMessage());
  64.  }
  65. }
  66. }


 
Après le déploiement de l'appli sur tomcat, on obtient l'erreur suivante :
 

Citation :

org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'


 
Nous avons cherché sur google et tenté toutes les solutions, mais rien n'y fait, nous sommes désespérés, au bord du suicide !
Si quelqu'un a une idée, elle est la bienvenue (je suis à 2 doigts d'étrangler mon binome)
Voilà, merci d'avance

mood
Publicité
Posté le 22-03-2007 à 15:52:28  profilanswer
 

n°1532313
the real m​oins moins
Posté le 22-03-2007 à 17:02:04  profilanswer
 

la config de ta datasource n'est pas bonne, lis la doc de la version de tomcat que tu utilises, ils ont changé entre 5.0 et 5.5
accessoirement, le driver que tu y references date de mathusalem.


Message édité par the real moins moins le 22-03-2007 à 17:02:19
n°1533142
Sinan
Posté le 24-03-2007 à 13:16:43  profilanswer
 

J'obtiens toujours la même ereur avec tomcat 5.0.28 et le driver com.mysql.jdbc.Driver
 
Une autre idée ?


Message édité par Sinan le 24-03-2007 à 13:16:56
n°1533905
Sinan
Posté le 26-03-2007 à 20:44:23  profilanswer
 

Ca marche nickel en suivant l'article sur le site de tomcat :jap:


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Aide : Connexion J2EE / Mysql

 

Sujets relatifs
[PHP/MYSQL] Affichage d'un champ dans une listboxAide sur un ALGO
a l'aide d'une liste box comment on peux acceder a la page selectionnéaide pour mes débuts en VB
avoir un renseignement sur création de menu via mysql..script csh besoin d'aide pour lire x lignes
Synchroniser les tables Users de 2 bases MySQLShell aide sur mon script
Aide pour la commande calcsAide pour un batch Mingw
Plus de sujets relatifs à : Aide : Connexion J2EE / Mysql


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR