title: Tomcat 7 cannot get a database connection with MySQL 5.5
body: <p>When trying to access a servlet that reads from the database i get the following error:</p>
  
  <pre><code>HTTP Status 500 -
  ...
  java.lang.NullPointerException
      com.pdq.sms.db.DatabaseAccess.getConnection(DatabaseAccess.java:39)
      com.pdq.sms.db.DataRow.Read(DataRow.java:79)
      com.kessel.controllers.Home.doPost(Home.java:50)
      com.kessel.controllers.Home.doGet(Home.java:39)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
  note The full stack trace of the root cause is available in the Apache Tomcat/7.0.26 logs.
  </code></pre>
  
  <p>Looking in the Tomcat log files i find this : "Name testapp is not bound in this Context" </p>
  
  <p>This is the relevant part of the <strong>server.xml</strong> </p>
  
  <pre><code>&lt;Host name="myserver.org" appBase="webapps/test" 
        unpackWARs="true" autoDeploy="true"&gt;
     &lt;Context path="/" docBase="testapp" reloadable="false"&gt;
        &lt;Resource name="jdbc/testapp" auth="Container"
            type="javax.sql.DataSource" maxActive="100" maxIdle="10" maxWait="10000"
            validationQuery="SELECT 1" driverClassName="com.mysql.jdbc.Driver"
            username="myuser" password="mypass"
            url="jdbc:mysql://localhost:3306/test_db?zeroDateTimeBehavior=convertToNull" /&gt;
      &lt;/Context&gt;"
  &lt;/Host&gt;"
  </code></pre>
  
  <p>I've also modified the <strong>04webapps.policy</strong> to give the application permission to connect:</p>
  
  <pre><code>   permission java.net.SocketPermission "127.0.0.1:3306", "resolve, connect";
  </code></pre>
  
  <p>User is setup properly on the MySQL server, i can manually connect and select, insert etc on the database in question. </p>
  
  <p>What am i not doing right ?</p>