Bonjour,
J'essaie d'utiliser les DataSource JDBC avec Tomcat 4.
J'ai suivi les instructions dans la doc de Tomcat et j'ai un :
--------------------
java.sql.SQLException: No suitable driver
        at java.sql.DriverManager.getDriver(DriverManager.java:243)
        at tyrex.jdbc.xa.EnabledDataSource.getConnection(EnabledDataSource.java:
233)
        at tyrex.jdbc.xa.EnabledDataSource.getConnection(EnabledDataSource.java:
204)
        at TestJDBCServlet.processRequest(TestJDBCServlet.java:60)
        at TestJDBCServlet.doGet(TestJDBCServlet.java:92)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
   
------------------

mon web.xml est comme suit:
-------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd";>

<web-app>
  <servlet>
    <servlet-name>TestJDBCServlet</servlet-name>
    <servlet-class>TestJDBCServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>TestJDBCServlet</servlet-name>
    <url-pattern>/servlet/TestJDBCServlet</url-pattern>
  </servlet-mapping>
  <resource-ref>
    <description>

    Resource reference to a factory for java.sql.Connection

    instances that may be used for talking to a particular

    database that is configured in the server.xml file.

  </description>
    <res-ref-name>

    jdbc/myDB

  </res-ref-name>
    <res-type>

    javax.sql.DataSource

  </res-type>
    <res-auth>

    Container

  </res-auth>
  </resource-ref>
</web-app>
----------------------------------
et dans mon server.xml il y a:
--------------------------------
<Context path="/web" docBase="web" 
         debug="2">
       
<Resource name="jdbc/myDB" auth="Container"
            type="javax.sql.DataSource"/>
  <ResourceParams name="jdbc/myDB">
    <parameter>
      <name>user</name>
      <value>root</value>
    </parameter>
    <parameter>
      <name>password</name>
      <value></value>
    </parameter>
    <parameter>
      <name>driverClassName</name>
      <value>org.gjt.mm.mysql.Driver</value>
    </parameter>
    <parameter>
      <name>driverName</name>
      <value>jdbc:mysql:///laliste</value>
    </parameter>
  </ResourceParams>
  </Context>
---------------------------------
Le code dans la servlet est:
---------------------------------
 Context initCtx = new InitialContext();
    Context envCtx = (Context) initCtx.lookup("java:comp/env");

    // Look up our data source

    DataSource ds = (DataSource) envCtx.lookup("jdbc/myDB");
    
    out.println("connexion...<p>");
    // Allocate and use a connection from the pool
    Connection conn = ds.getConnection();
    out.println("ok<p>");
    // ... use this connection to access the database ...
    Statement st = conn.createStatement();
    ResultSet rs = st.executeQuery("select * from users");
    if(rs.next())
    {
        out.println("user: "+rs.getString("firstname"));
    }
    else
        out.println("rien trouv�");
    
    conn.close();
------------------------------

Le message d'erreur laisse penser que le DriverManager ne trouve pas de driver pour ce 
format d'URL mais le m�me code en utilisant directement le driver JDBC au lieu d'une 
DataSource, avec l'URL d�finie dans le fichier server.xml fonctionne parfaitement.

Je s�che alors si quelqu'un a une id�e avant que je ne reprenne mon gestionnaire de 
pool � moi...

Patrice

-- 


-- Use Opera, the most user-friendly browser on earth --

_______________________________________________
Download the free Opera browser at http://www.opera.com/

Powered by Outblaze

Répondre à