title: Problems with JDBC Driver & Tomcat
body: <p>Having some problems trying to setup a DB connection from a servlet.</p>
  
  <p>I have the following class that handles the DB connection in the servlet but I keep getting an NullPointerException for <code>Class.forName()</code>.</p>
  
  <p>DB Util Class:</p>
  
  <pre><code>public class Database {
  
      private static Connection connection = null;
  
      /**
       * 
       * @return
       */
      public static Connection getConnection(){
          if(connection!=null){
              return connection;
          } else {
              try {
                  Properties db_properties = new Properties();
                  InputStream inStream = Database.class.getClassLoader().getResourceAsStream("/db.properties");
                  db_properties.load(inStream);
                  //String dbDriver = db_properties.getProperty("driver").trim();
                  String url = db_properties.getProperty("url").trim();
                  String dbUser = db_properties.getProperty("user").trim();
                  String dbPass = db_properties.getProperty("pass").trim();
                  Class.forName("com.mysql.jdbc.Driver");
                  connection = DriverManager.getConnection(url,dbUser,dbPass);
              } catch (IOException e) {
                  e.printStackTrace();
              } catch (ClassNotFoundException e) {
                  e.printStackTrace();
              } catch (SQLException e) {
                  e.printStackTrace();
              }
          }
          return connection;
      }
  }
  </code></pre>
  
  <p>With the following properties file (I tried hardcoding the driver in and still get the same error!):</p>
  
  <pre><code>driver=com.mysql.jdbc.Driver
  url=jdbc:mysql://localhost:8889/gymbuddy
  user=Mathan
  pass=PYCCmcPDAFSj7N9B
  </code></pre>
  
  <p>And I get the following Stack trace:</p>
  
  <pre><code>SEVERE: Allocate exception for servlet BuddyController
  java.lang.NullPointerException
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:171)
      at com.mathanv.gb.util.Database.getConnection(Database.java:35)
      at com.mathanv.gb.dao.BuddyDao.&lt;init&gt;(BuddyDao.java:35)
      at com.mathanv.gb.controller.BuddyController.&lt;init&gt;(BuddyController.java:29)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
      at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
      at java.lang.Class.newInstance0(Class.java:357)
      at java.lang.Class.newInstance(Class.java:310)
      at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:138)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1137)
      at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:858)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
      at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
      at java.lang.Thread.run(Thread.java:680)
  </code></pre>
  
  <p>I'm trying to send a post request from a Android client. The HTTPpost request seems to work! But getting the connection gives me the above exception! Help!</p>
  
  <p>The following is my Servlet layout:</p>
  
  <p><img src="https://i.stack.imgur.com/sKW5t.png" alt="Servlet Layout"></p>
  
  <p>Let me know if you need any more information!</p>