DataSource no Tomcat

Ola pessoal, sou novo nessa área e estou apanhando muito disso, faz 3 dias que estou procurando a solução e não acho.
Estou tentando criar um data source para conectar em um Mysql dentro do tomcat, mas a única coisa que consigo é:

Ocorreu um erro em: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class ‘’ for connect URL ‘null’

Aparentemente, ele não consegue pegar a url que está dentro do arquivo “server.xml”.

versão do Tomcat: 5.5.20
versão do Mysql: 5.0.22

Estou postando os codigos que ahuda né??

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">

	<resource-ref>
		<res-ref-name>jdbc/address</res-ref-name>
		<res-type>javax.sql.DataSource</res-type>
		<res-auth>Container</res-auth>
	</resource-ref>

</web-app>

server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server>
  <Listener className="org.apache.catalina.core.AprLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
  <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener"/>
  <GlobalNamingResources>
    <Environment
      name="simpleValue"
      type="java.lang.Integer"
      value="30"/>
    <Resource
      auth="Container"
      description="User database that can be updated and saved"
      name="UserDatabase"
      type="org.apache.catalina.UserDatabase"
      pathname="conf/tomcat-users.xml"
      factory="org.apache.catalina.users.MemoryUserDatabaseFactory"/>
    <Resource
      name="jdbc/address"
      type="javax.sql.DataSource"
      password="root"
      driverClassName="com.mysql.jdbc.Driver"
      maxIdle="2"
      maxWait="5000"
      username="root"
      url="jdbc:mysql://localhost:3306/address"
      maxActive="4"/>
  </GlobalNamingResources>
  <Service
      name="Catalina">
    <Connector
        port="8080"
        redirectPort="8443"
        minSpareThreads="25"
        connectionTimeout="20000"
        maxSpareThreads="75"
        maxThreads="150">
    </Connector>
    <Connector
        port="8009"
        redirectPort="8443"
        connectionTimeout="-1"
        protocol="AJP/1.3">
    </Connector>
    <Engine
        defaultHost="localhost"
        name="Catalina">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"/>
      <Host
          appBase="webapps"
          name="localhost">
        <Context
            path="/WebApplication3"
            reloadable="true">
          <Resource
            auth="Container"
            name="jdbc/address"
            type="javax.sql.DataSource"/>
        </Context>
      </Host>
    </Engine>
  </Service>
</Server>

e a jsp que estou tentando obter a conexão:

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import="java.sql.*, javax.sql.*, javax.naming.*"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Uso de DataSources</title>
    </head>
    <body>

    <h1>Usando DataSource</h1>
    <%
        javax.sql.DataSource ds=null;
        Connection conn=null;
        ResultSet result=null;
        Statement stmt=null;
        ResultSetMetaData rsmd=null;
        
        try
        {
            Context context = new InitialContext();
		Context envCtx= (Context) context.lookup("java:comp/env");
		ds=(DataSource)envCtx.lookup("jdbc/address");
            if (ds != null)
            {
                conn=ds.getConnection();
                stmt=conn.createStatement();
                result=stmt.executeQuery("select * from addressList");
            }
		else
		{
			out.write("esta nulo");
		}
        }catch(Exception e)
        {
            out.write("Ocorreu um erro em: "+e);
        }
    int columns=0;
    try
    {
        if (rsmd!=null){
        rsmd=result.getMetaData();
        columns=rsmd.getColumnCount();}
        else
           System.out.println("esta nulo");
    }catch (SQLException e)
    {
        System.out.println("Ocorreu um erro "+e);
    }
    %>
  </table>
    </body>
</html>

A linha que está ocorrendo o erro é: conn=ds.getConnection();
pois retorna null na url do banco.

so observações: a minha base de dados é address e a tabela é addresslist

Obrigado!!

Você colocou o jar do mysql no common/lib do Tomcat ???

ola hildebrando!!

Primeiramente obrigado por responder o meu tópico.
Já coloquei sim o jar do mysql no common/lib do tomcat. Mas mesmo assim não resolveu.
O jar que estou usando é: mysql-connector-java-5.0.0-beta-bin.jar

Teria mais alguma sugestão?

Obrigado!!!

Acho q nao é sua conexao q esta com erro nao…

Verifique se o seu DataSource num tá null… pq dai logico a conexao vai tah null tbm… acho q o lookup pode estar dando erro…

Aki um exemplo de xml para criar um DataSource…

server.xml

[code]

factory org.apache.commons.dbcp.BasicDataSourceFactory
<!-- Maximum number of dB connections in pool. Make sure you
     configure your mysqld max_connections large enough to handle
     all of your db connections. Set to 0 for no limit.
     -->
<parameter>
  <name>maxActive</name>
  <value>100</value>
</parameter>

<!-- Maximum number of idle dB connections to retain in pool.
     Set to 0 for no limit.
     -->
<parameter>
  <name>maxIdle</name>
  <value>30</value>
</parameter>

<!-- Maximum time to wait for a dB connection to become available
     in ms, in this example 10 seconds. An Exception is thrown if
     this timeout is exceeded.  Set to -1 to wait indefinitely.
     -->
<parameter>
  <name>maxWait</name>
  <value>10000</value>
</parameter>

<!-- MySQL dB username and password for dB connections  -->
<parameter>
 <name>username</name>
 <value>javauser</value>
</parameter>
<parameter>
 <name>password</name>
 <value>javadude</value>
</parameter>

<!-- Class name for mm.mysql JDBC driver -->
<parameter>
   <name>driverClassName</name>
   <value>org.gjt.mm.mysql.Driver</value>
</parameter>

<!-- The JDBC connection url for connecting to your MySQL dB.
     The autoReconnect=true argument to the url makes sure that the
     mm.mysql JDBC Driver will automatically reconnect if mysqld closed the
     connection.  mysqld by default closes idle connections after 8 hours.
     -->
<parameter>
  <name>url</name>
  <value>jdbc:mysql://localhost:3306/javatest?autoReconnect=true</value>
</parameter>
[/code]

web.xml

<?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>
  <description>MySQL Test App</description>
  <resource-ref>
      <description>DB Connection</description>
      <res-ref-name>jdbc/TestDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
</web-app>

Teste code

<html>
  <head>
    <title>DB Test</title>
  </head>
  <body>

  <%
    foo.DBTest tst = new foo.DBTest();
    tst.init();
  %>

  <h2>Results</h2>
    Foo <%= tst.getFoo() %><br/>
    Bar <%= tst.getBar() %>

  </body>
</html>

[code]
package foo;

import javax.naming.;
import javax.sql.
;
import java.sql.*;

public class DBTest {

String foo = “Not Connected”;
int bar = -1;

public void init() {
try{
Context ctx = new InitialContext();
if(ctx == null )
throw new Exception(“Boom - No Context”);

  DataSource ds = 
        (DataSource)ctx.lookup(
           "java:comp/env/jdbc/TestDB");

  if (ds != null) {
    Connection conn = ds.getConnection();
          
    if(conn != null)  {
        foo = "Got Connection "+conn.toString();
        Statement stmt = conn.createStatement();
        ResultSet rst = 
            stmt.executeQuery(
              "select id, foo, bar from testdata");
        if(rst.next()) {
           foo=rst.getString(2);
           bar=rst.getInt(3);
        }
        conn.close();
    }
  }
}catch(Exception e) {
  e.printStackTrace();
}

}

public String getFoo() { return foo; }
public int getBar() { return bar;}
}[/code]