web services.Error:com.mysql.jdbc.CommunicationsException:通信链路故障java.io.eofeException

web services.Error:com.mysql.jdbc.CommunicationsException:通信链路故障java.io.eofeException,mysql,web-services,jdbc,Mysql,Web Services,Jdbc,我正在为销售代表创建RESTfulWeb服务,以便他们从UI登录并通过JDBC连接到Mysql数据库。在Windows10上使用动态web服务-web模块版本2.5、ApacheTomcat服务器8.0。我用Java类编写了查询,并尝试连接到数据库。运行tomcat服务器时。。它将进入ui,单击“提交”按钮时,下一个操作是连接到DB,但其抛出: UI上及其控制台中的Java.null.point.exception com.mysql.jdbc.CommunicationsException:通

我正在为销售代表创建RESTfulWeb服务,以便他们从UI登录并通过JDBC连接到Mysql数据库。在Windows10上使用动态web服务-web模块版本2.5、ApacheTomcat服务器8.0。我用Java类编写了查询,并尝试连接到数据库。运行tomcat服务器时。。它将进入ui,单击“提交”按钮时,下一个操作是连接到DB,但其抛出:

UI上及其控制台中的Java.null.point.exception
com.mysql.jdbc.CommunicationsException:通信链路故障 由于基础异常:*开始嵌套异常**
java.io.EOFException

可能的重复可能的重复
public class loginservlet6_1 extends HttpServlet {

    private static final long serialVersionUID = 1L;
    Connection con=null;
    Statement st=null;
    ResultSet rs=null;

    public void init(ServletConfig config)
    {
        try
        {
            System.out.println("Database connectionestablishment");
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection("jdbc:mysql://localhost:1002/root","root","root");
    //(jdbc:mysql://localhost:portnum/dbname , username,password)
            System.out.println("Database conn established");
        }
        catch(Exception e)
            {
                System.out.println(e);
            }
    }



    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        try
        {
            st = con.createStatement();
                    rs = st.executeQuery("select UserName,Password from reps where UserName='"+username+"' and Password='"+password+"'");
            while(rs.next())
            {
                System.out.println("Username : "+rs.getString(1)+"  Password : "+rs.getString(2));

                if(username.equals(rs.getString(1)) && password.equals(rs.getString(2))){  
                JOptionPane.showMessageDialog(null,"Login Successful");
                response.sendRedirect("/login.html");
                }
                else
                {
                    JOptionPane.showMessageDialog(null,"Login Not Successful");
                    /*RequestDispatcher rd = request.getRequestDispatcher("/RegisterServlet");
                    rd.forward(request, response);
                    */
                    response.sendRedirect("/TestDemo6/login.html");
                }

            }


        }
        catch(Exception e){
            out.println(e);
        }
    }
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);

    }
    public void destroy()
    {
        try {
            rs.close();
        } catch (SQLException se) {
            se.printStackTrace();
        }
        try {
            st.close();
        } catch (SQLException e) {
                    e.printStackTrace();
                }
        try {con.close();
        } catch (SQLException e) {
                e.printStackTrace();
        }
    }
}