title: SEVERE: Servlet.service() for servlet [SqlGatewayServlet] in context with path [/DEV-JDBC] threw exception
body: <p>My question is very similar to [Link]: (<a href="https://stackoverflow.com/questions/11496229/why-servlet-service-for-servlet-xyz-in-context-with-path-abc-threw-except">Why Servlet.service() for servlet [XYZ] in context with path [/ABC] threw exception</a>)  But I don't think it was resolved.</p>
  
  <p>This is a simple SQL gateway application, on my personal computer localhost it works fine.  However, when I upload the war file to server it throws this exception</p>
  
  <p><code>org.apache.catalina.core.StandardWrapperValve invoke
  SEVERE: Servlet.service() for servlet [SqlGatewayServlet] in context with path [/DEV-JDBC] threw exception
  java.lang.NullPointerException
  at sql.SqlGatewayServlet.do
  </code></p>
  
  <p><code>java.lang.NullPointerException
      sql.SqlGatewayServlet.doPost(SqlGatewayServlet.java:34)</code></p>
  
  <p>Line: 34 is <code>Statement statement = connection.createStatement();</code></p>
  
  <p>SqlGatewayServlet</p>
  
  <pre><code>public class SqlGatewayServlet extends HttpServlet {
  
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
  
      String sqlStatement = request.getParameter("sqlStatement");
      String sqlResult = "";
  
  
  
      try{
          ConnectionPool pool = ConnectionPool.getInstance();
          Connection connection = pool.getConnection();
  
          // create a statement
          Statement statement = connection.createStatement();
  
          // parse the SQL string
          sqlStatement = sqlStatement.trim();
          if(sqlStatement.length() &gt; 6){
  
              String sqlType = sqlStatement.substring(0, 6);
              if(sqlType.equalsIgnoreCase("select")){
  
                  // create the HTML for the result set
                  ResultSet resultSet = statement.executeQuery(sqlStatement);
                  sqlResult = SQLUtil.getHtmlTable(resultSet);
                  resultSet.close();
  
              }else{
  
                  int i = statement.executeUpdate(sqlStatement);
                  // a DDL statement
                  if(i == 0){
                      sqlResult = "The statement executed successfully";
                  }else{
                      sqlResult = "The statment executed sucessfully.&lt;br&gt;"
                              + i + "row(s) affected.";
                  }                   
              }
          statement.close();
          connection.close();
  
          }
  
      }catch( SQLException e){
          sqlResult = "Error executing the SQL statement: &lt;br&gt;"
                  + e.getMessage();
  
      }
      HttpSession session = request.getSession();
      session.setAttribute("sqlResult", sqlResult);
      session.setAttribute("sqlStatement", sqlStatement);
  
      String url = "/index.jsp";
  
      RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
  
      dispatcher.forward(request, response);
  }
  
  }
  </code></pre>
  
  <p>context.xml</p>
  
  <pre><code>&lt;Context path="/DEV-JDBC"&gt;
  
  &lt;Resource name="jdbc/uplink_project" auth="Container" 
      maxActive="100" maxIdle="30" maxWait="10000" 
      username="xxxxx" password="xxxxxx" 
      driverClassName="com.mysql.jdbc.Driver" 
      url="jdbc:mysql://localhost:2082/uplink_project?autoReconnect=true" 
      logAbandoned="true" removeAbandoned="true" 
      removeAbandonedTimeout="60" type="javax.sql.DataSource" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>Is there something wrong with my setup? or its the server problem?  Please let me know what other information you need.</p>
  
  <p>Thank in advance</p>