title: Tomcat and MYSQL porting to AWS
body: <p>I have a working java 7 app that runs on tomcat 7 and MYSQL. I am trying to get it running on the basic (free tier) platform offered by Amazon AWS. I have succesfully loaded data to the RDS instance of MYSQL Community and set up an Elastic Beanstalk instance where basic JSPs are running correctly.</p>
  
  <p>I am new to AWS so main problem should be my lack of knowledge.</p>
  
  <p>I am not able to connect to the database from my code.</p>
  
  <p>This is the code I am using to create the connection pool:</p>
  
  <pre><code>package com.authz.pap;
  
  import javax.naming.Context;
  import javax.naming.InitialContext;
  import javax.naming.NamingException;
  import javax.sql.DataSource;
  
  public class DBConnections {
      private static DataSource dataSource;
  
      private static final DBConnections instance = new DBConnections();
  
      static
      {
          try
          {
              Context c = new InitialContext();
              dataSource = (DataSource)c.lookup("java:comp/env/jdbc/authzDB");
          }
          catch (Exception e)
          {
              dataSource = null;
          }
      }
      private DBConnections()
      {
      }
  
      public static DBConnections getInstance()
      {
          return instance;
      }
  
      public static DataSource getGeoServDS() {
          //if(dataSource==null) instance = new DBConnections();
          return dataSource;
      }
  
  }
  </code></pre>
  
  <p>And this:</p>
  
  <pre><code>public DbCon() {
  
      conn=null;
      ProcessStatus stat = new ProcessStatus();
      stat.function="DbCon.DbCon";
      stat.message = "Initializing DB";
      stat.retcode=0;
      stat.record();
      try {
          conn=DBConnections.getGeoServDS().getConnection();
          conn.setAutoCommit(false);
      } catch (Exception e) {
          stat.message = e.toString();
          stat.retcode=-1;
          stat.record();
      }
  }
  </code></pre>
  
  <p>And this is the content of the context.xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context antiJARLocking="true" path="/rest"&gt;
    &lt;Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="8" maxIdle="4" name="jdbc/authzDB" password="xxxx" type="javax.sql.DataSource" url="jdbc:mysql://x.x.x.x:3306/authzDB?autoReconnect=true&amp;amp;allowMultiQueries=true" username="root"/&gt;
    &lt;ResourceLink global="jdbc/authzDB" name="jdbc/authzDB" type="javax.sql.DataSource"/&gt;
  &lt;/Context&gt;
  </code></pre>
  
  <p>What I get is a <code>java.lang.NullPointerException</code> on DB initialization.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>UPDATE:</p>
  
  <p>This is the content of the web.xml file:</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" id="WebApp_ID" version="2.5"&gt;
    &lt;display-name&gt;paprest&lt;/display-name&gt;
    &lt;servlet&gt;
      &lt;servlet-name&gt;PAP rest interface&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
        &lt;param-value&gt;com.authz.pap.intfc&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
    &lt;/servlet&gt;
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;rest interface&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>