SEVERE: Servlet.service () for servlet [SqlGatewayServlet] in the context of path [/ DEV-JDBC] threw the exception

My question is very similar to [Link]: (Why Servlet.service() for servlet [XYZ] in context with path [/ABC] threw exception) But I don't think it was resolved.

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

org.apache.catalina.core.StandardWrapperValve invoke SEVERE: Servlet.service() for servlet [SqlGatewayServlet] in context with path [/DEV-JDBC] threw exception java.lang.NullPointerException at

java.lang.NullPointerException sql.SqlGatewayServlet.doPost(

Line: 34 is Statement statement = connection.createStatement();


public class SqlGatewayServlet extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String sqlStatement = request.getParameter("sqlStatement");
    String sqlResult = "";

        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() > 6){

            String sqlType = sqlStatement.substring(0, 6);

                // create the HTML for the result set
                ResultSet resultSet = statement.executeQuery(sqlStatement);
                sqlResult = SQLUtil.getHtmlTable(resultSet);


                int i = statement.executeUpdate(sqlStatement);
                // a DDL statement
                if(i == 0){
                    sqlResult = "The statement executed successfully";
                    sqlResult = "The statment executed sucessfully.<br>"
                            + i + "row(s) affected.";


    }catch( SQLException e){
        sqlResult = "Error executing the SQL statement: <br>"
                + 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);



<Context path="/DEV-JDBC">

<Resource name="jdbc/uplink_project" auth="Container"
    maxActive="100" maxIdle="30" maxWait="10000"
    username="xxxxx" password="xxxxxx"
    logAbandoned="true" removeAbandoned="true"
    removeAbandonedTimeout="60" type="javax.sql.DataSource" />

Is there something wrong with my setup? or its the server problem? Please let me know what other information you need.

Thank in advance

If there is a null pointer exception in the following statement:

   Statement statement = connection.createStatement();

then it means that your connection object is null.

As you are initializing your connection object from the ConnectionPool class. So make sure its getConnection method returns a valid connection object:

    ConnectionPool pool = ConnectionPool.getInstance();
    Connection connection = pool.getConnection();

You need to debug your ConnectionPool class.