title: JNDI Can't Create a JDBC Connection on Tomcat 6
body: <p>I'm getting this error when I try to view the page:</p>
  
  <pre><code>SQLException: Cannot create JDBC driver of class '' for connect URL 'null'
  </code></pre>
  
  <p>I have the following /WEB-INF/web.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app&gt;
      &lt;display-name&gt;WSwartzendruber.net&lt;/display-name&gt;
      &lt;description&gt;Personal Website&lt;/description&gt;
      &lt;!-- Servlet stuff --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;PostgresTest&lt;/servlet-name&gt;
          &lt;servlet-class&gt;PostgresTest&lt;/servlet-class&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;PostgresTest&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/servlets/postgrestest&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;!-- JNDI --&gt;
      &lt;resource-ref&gt;
          &lt;description&gt;PostgreSQL Data Source&lt;/description&gt;
          &lt;res-ref-name&gt;jdbc/db_website&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;/web-app&gt;
  </code></pre>
  
  <p>I have this in /META-INF/context.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context reloadable="true"&gt;
      &lt;Resource name="jdbc/db_website" auth="Container" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://localhost:5432/db_website" username="website"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>And here is the test code:</p>
  
  <pre><code>import java.io.*;
  import java.sql.*;
  import javax.naming.*;
  import javax.servlet.*;
  import javax.servlet.http.*;
  import javax.sql.*;
  import org.wswartzendruber.website.access.*;
  
  public class PostgresTest extends HttpServlet
  {
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException
      {
          response.setContentType("text/plain");
  
          try
          {
              Context initialContext = new InitialContext();
              Context context = (Context)initialContext.lookup("java:comp/env");
              DataSource dataSource = (DataSource)context.lookup("jdbc/db_website");
              Connection connection = dataSource.getConnection();
              NewsCategory[] newsCategory = NewsCategory.getNewsCategories(connection);
  
              connection.close();
          }
          catch (NamingException e)
          {
              response.getWriter().println("ERROR: We have naming problems!");
          }
          catch (SQLException se)
          {
              response.getWriter().println("ERROR: SQLException: " + se.getMessage());
          }
          catch (AccessException ae)
          {
              response.getWriter().println("ERROR: AccessException: " + ae.getMessage());
          }
      }
  }
  </code></pre>
  
  <p>I'm at a loss for what the issue is.  I already have /usr/share/tomcat-6/lib/postgresql-8.4-702.jdbc4.jar in place.  Moving it to /WEB-INF/lib makes no difference.  It seems to me that it can see the resource entry in WEB-INF/web.xml, but that it can't pull the details from META-INF/context.xml.  Assigning a password there also seems to make no difference.</p>
  
  <p>I'm up for whatever you guys have.</p>
  
  <hr>
  
  <p><strong>Update</strong>: here is the full stacktrace:</p>
  
  <pre><code>Sep 19, 2010 7:01:36 PM org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet PostgresTest threw exception
  java.io.IOException: org.apache.tomcat.dbcp.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL 'null'
      at PostgresTest.doGet(PostgresTest.java:23)
      at javax.servlet.http.HttpServlet.service(Unknown Source)
      at javax.servlet.http.HttpServlet.service(Unknown Source)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Unknown Source)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(Unknown Source)
      at org.apache.catalina.core.StandardWrapperValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardContextValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardHostValve.invoke(Unknown Source)
      at org.apache.catalina.valves.ErrorReportValve.invoke(Unknown Source)
      at org.apache.catalina.core.StandardEngineValve.invoke(Unknown Source)
      at org.apache.catalina.connector.CoyoteAdapter.service(Unknown Source)
      at org.apache.jk.server.JkCoyoteHandler.invoke(Unknown Source)
      at org.apache.jk.common.HandlerRequest.invoke(Unknown Source)
      at org.apache.jk.common.ChannelSocket.invoke(Unknown Source)
      at org.apache.jk.common.ChannelSocket.processConnection(Unknown Source)
      at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(Unknown Source)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(Unknown Source)
      at java.lang.Thread.run(Thread.java:636)
  Caused by: 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 PostgresTest.doGet(PostgresTest.java:17)
      ... 17 more
  Caused by: java.lang.NullPointerException
      at org.postgresql.Driver.parseURL(Driver.java:567)
      at org.postgresql.Driver.acceptsURL(Driver.java:412)
      at java.sql.DriverManager.getDriver(DriverManager.java:268)
      at org.apache.tomcat.dbcp.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1437)
      ... 20 more
  </code></pre>