电话号码输入字符串的数字格式例外

时间:2013-06-14 09:56:34

标签: string servlets updating phone-number numberformatexception

错误的电话号码字段...虽然我给了long或int它给出了相同的错误...请帮忙 我从表格中获取所有参数,但不幸的是这个电话号码没有得到更新..它超出了int的范围,所以我尝试了很长但没有用...

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String update = " UPDATE cust_info_table SET cust_fname=?,cust_lname=?, phone_num=?, email_id=?, address=? WHERE cust_id=? ";
    try{

        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mutualfund", "root", "");

        PreparedStatement ps = con.prepareStatement(update);
        String fname = request.getParameter("fname");
          String lname = request.getParameter("lname");

          long phn = Integer.parseInt(request.getParameter("phn"));

          String mail = request.getParameter("mail");
          String addr = request.getParameter("addr");
          String uid = request.getParameter("uid");
        ps.setString(1,fname);
        ps.setString(2, lname);
        ps.setLong(3, phn);

        ps.setString(4, mail);
        ps.setString(5, addr);
        ps.setString(7,uid);
        ps.executeUpdate();
        con.close();
        response.sendRedirect("welcome.jsp?name="+uid);
    } 
    catch (Exception ex)
    {
        Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
    }

}

1 个答案:

答案 0 :(得分:0)

首先尝试以下方式.. long phn = Integer.parseInt(“12312312”); 并注意到这一点......

    ps.setString(4, mail);
    ps.setString(5, addr);
    ps.setString(7,uid);

它应该是“ps.setString(6,uid);”。