简体   繁体   English

严重:路径为[/ DEV-JDBC]的上下文中的Servlet [SqlGatewayServlet]的Servlet.service()抛出异常

[英]SEVERE: Servlet.service() for servlet [SqlGatewayServlet] in context with path [/DEV-JDBC] threw 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. 我的问题与[Link]非常相似:( 为什么在路径[/ ABC]的上下文中,用于Servlet [XYZ]的Servlet.service()抛出异常 ),但我认为这没有解决。

This is a simple SQL gateway application, on my personal computer localhost it works fine. 这是一个简单的SQL网关应用程序,在我的个人计算机localhost上运行正常。 However, when I upload the war file to server it throws this exception 但是,当我将war文件上传到服务器时,它将引发此异常

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

java.lang.NullPointerException sql.SqlGatewayServlet.doPost(SqlGatewayServlet.java:34)

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

SqlGatewayServlet SqlGatewayServlet

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() > 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.<br>"
                            + i + "row(s) affected.";
                }                   
            }
        statement.close();
        connection.close();

        }

    }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.xml 的context.xml

<Context path="/DEV-JDBC">

<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" />

Is there something wrong with my setup? 我的设置有问题吗? or its the server problem? 还是服务器问题? Please let me know what other information you need. 请让我知道您还需要什么其他信息。

Thank in advance 预先感谢

可能问题出在getConnection()方法上的ConnectionPool类中,如果connectionnull

If there is a null pointer exception in the following statement: 如果以下语句中存在空指针异常:

   Statement statement = connection.createStatement();

then it means that your connection object is null. 则表示您的连接对象为null。

As you are initializing your connection object from the ConnectionPool class. 当您从ConnectionPool类初始化连接对象时。 So make sure its getConnection method returns a valid connection object: 因此,请确保其getConnection方法返回有效的连接对象:

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

You need to debug your ConnectionPool class. 您需要调试ConnectionPool类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 严重:Servlet [package]的Servlet.service()在路径[/ portal]的上下文中引发了异常java.lang.NullPointerException - SEVERE: Servlet.service() for servlet [package] in context with path [/portal] threw exception java.lang.NullPointerException 严重:servlet [ProfileServlet] 的 Servlet.service() 在路径为 [/Homework] 的上下文中抛出异常 java.lang.NumberFormatException: null - SEVERE: Servlet.service() for servlet [ProfileServlet] in context with path [/Homework] threw exception java.lang.NumberFormatException: null servlet [dispatcher] 的 Servlet.service() 在路径为 [/***] 的上下文中抛出异常 - Servlet.service() for servlet [dispatcher] in context with path [/***] threw exception 严重:servlet [spring] 的 Servlet.service() 在路径 [/com.elearning.webapp] 的上下文中抛出异常 [请求处理失败; - SEVERE: Servlet.service() for servlet [spring] in context with path [/com.elearning.webapp] threw exception [Request processing failed; Servlet.service() for servlet [...] in context with path [/...] 抛出异常 [Servlet 执行抛出异常] 具有根本原因 - Servlet.service() for servlet [...] in context with path [/...] threw exception [Servlet execution threw an exception] with root cause servlet [dispatcherServlet] 在路径 [] 的上下文中的 Servlet.service() 引发异常 [处理程序调度失败; - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; servlet [jsp] 的 Servlet.service() 抛出异常 - Servlet.service() for servlet [jsp] threw exception 严重:Servlet [jsp]的Servlet.service()抛出异常java.lang.NumberFormatException - SEVERE: Servlet.service() for servlet [jsp] threw exception java.lang.NumberFormatException Struts 2:SEVERE:Servlet默认的Servlet.service()抛出异常java.lang.NullPointerException - Struts 2: SEVERE: Servlet.service() for servlet default threw exception java.lang.NullPointerException Servlet.service() 用于 servlet [dispatcherServlet] 在上下文中的路径 - Servlet.service() for servlet [dispatcherServlet] in context with path
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM