jsp中的空点异常如何解决

时间:2019-07-14 16:45:33

标签: java jsp

在路径为[/ HomeWorkSqlConnection]的上下文中,严重程度为[http-nio-8084-exec-275] org.apache.catalina.core.StandardWrapperValve.invoke Servlet [insertdata]的Servlet.service()  java.lang.NullPointerException

    try {

        CreateConnection();
        CreatesStatement();

        String name=request.getParameter("name");
        int age=Integer.parseInt(request.getParameter("age"));
        String address=request.getParameter("address");

        String sql="insert into user_data(name,age,address)"
                + " values('"+name+"','"+age+"','"+address+"')";

        st.executeUpdate(sql);
    } catch (SQLException e) {
         System.out.println(e.getMessage());

    }

}






private Connection cn;
public void CreateConnection () throws SQLException{
    try{
         String path="jdbc:mysql://localhost/servlet_db";
         cn=DriverManager.getConnection(path,"root","");
    }
    catch(SQLException e){
        System.out.println(e.getMessage());
    }

}

private Statement st;
public void CreatesStatement (){
    try {
        st=cn.createStatement();
    } catch (SQLException ex) {
        Logger.getLogger(InsertData.class.getName()).log(Level.SEVERE, null, ex);
    }
}

}

0 个答案:

没有答案