title: Cannot create JDBC driver of class '' for connect URL 'null' and NullPointerException
body: <p>im using Spring, learning with servlets and all that webstuff, i'm trying to create a simple servlet for connecting to mysql server.. here is my code:</p>
  
  <p>AccesoDB:</p>
  
  <pre><code>package es.prueba.servlet;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import java.sql.Connection;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.servlet.ServletConfig;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.sql.DataSource;
  
  /**
   * Servlet implementation class AccesoDB
   */
  public class AccesoDB extends HttpServlet {
      private static final long serialVersionUID = 1L;
      private DataSource ds = null;
      ResultSet rs;
      Context ctx;
  
      /**
       * @see HttpServlet#HttpServlet()
       */
      public AccesoDB() {
          super();
          // TODO Auto-generated constructor stub
      }
  
      @Override
      public void init(ServletConfig conf) throws ServletException {
          super.init(conf);
  
          try {
              ctx = new InitialContext();
              ds = (DataSource) ctx.lookup("java:comp/env/jdbc/AccesoBD");
          } catch ( NamingException e) {
              e.printStackTrace();
          }
  
      }
  
      /**
       * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          response.setContentType("text/html");
  
          Connection connection = null;
  
          synchronized(ds) {
              try{
                  connection = ds.getConnection();
  
                  PrintWriter out = response.getWriter();
                  String query = null;
                  Statement stmt;
                  query = "SELECT * FROM test";
                  stmt = connection.createStatement();
  
                  rs = stmt.executeQuery(query);
                  out.println(rs.toString());
  
                  connection.close();
              }catch (SQLException e) {
                  e.printStackTrace();
              }
          }
      }
  
      /**
       * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
       */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          doGet(request,response);
      }
  
  }
  </code></pre>
  
  <p>context.xml:</p>
  
  <pre><code> &lt;Context path="/AccesoDB" docBase=" AccesoBD "
      debug="5" reloadable="true" crossContext="true"&gt;
      &lt;Resource name="jdbc/ AccessoBD " auth="Container"
          type="javax.sql.DataSource" maxActive="100"
          maxIdle="30" maxWait="10000" username="test"
          password="test"
          driverClassName="com.mysql.jdbc.Driver"
          url="jdbc:mysql://localhost:3306/dbaplicacion"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>web.xml:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
    &lt;display-name&gt;elTiempo&lt;/display-name&gt;
    &lt;servlet&gt;
      &lt;display-name&gt;AjaxExample&lt;/display-name&gt;
      &lt;servlet-name&gt;AjaxExample&lt;/servlet-name&gt;
      &lt;servlet-class&gt;es.prueba.servlet.AjaxExample&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;AjaxExample&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/AjaxExample&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
    &lt;welcome-file-list&gt;
      &lt;welcome-file&gt;holaMundo.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.html&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.htm&lt;/welcome-file&gt;
      &lt;welcome-file&gt;default.jsp&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;
    &lt;resource-ref&gt;
      &lt;res-ref-name&gt;jdbc/AccesoBD&lt;/res-ref-name&gt;
      &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
      &lt;res-auth&gt;Container&lt;/res-auth&gt;
    &lt;/resource-ref&gt;
    &lt;servlet&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;display-name&gt;AccesoDB&lt;/display-name&gt;
      &lt;servlet-name&gt;AccesoDB&lt;/servlet-name&gt;
      &lt;servlet-class&gt;es.prueba.servlet.AccesoDB&lt;/servlet-class&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;AccesoDB&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/AccesoDB&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Here is the trace of the error:</p>
  
  <pre><code>    org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1452)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
      at es.prueba.servlet.AccesoDB.doGet(AccesoDB.java:62)
      at es.prueba.servlet.AccesoDB.doPost(AccesoDB.java:83)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:643)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      at java.lang.Thread.run(Thread.java:744)
  Caused by: java.lang.NullPointerException
      at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:524)
      at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:493)
      at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
      at java.sql.DriverManager.getDriver(DriverManager.java:262)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
      ... 18 more
  </code></pre>
  
  <p>The error is in the line:</p>
  
  <pre><code>connection = ds.getConnection();
  </code></pre>
  
  <p>But i can't figure it out, as i said before, i'm learning and the other threads doesnt help me.</p>
  
  <p>EDIT: I also have this error when launching Tomcat, dunno if it matters:</p>
  
  <pre><code>java.lang.IllegalArgumentException: El Documento base C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\context no existe o no es un directorio legible
      at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:142)
      at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4320)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4489)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
      at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
      at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
      at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
      at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
      at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
      at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
      at org.apache.catalina.core.StandardService.start(StandardService.java:525)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:606)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
  </code></pre>