0

getting an error with phone number field... though i gave long or int it gives same error... please help I am getting all the parameters from a form but unfortunately this phone number is not getting updated.. its out of range of int so i tried long but no use...

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);
    }

}
APPU cool
  • 45
  • 1
  • 3
  • 9
  • what is the error? And where does the error occurs? – MaVRoSCy Jun 14 '13 at 10:05
  • 1
    And why does a telephone be of type Long? Cant a telephone be somethine like `00355 0077665544`? How Can you represent that in Long datatype? I would suggest you change that into a varchar – MaVRoSCy Jun 14 '13 at 10:08
  • thank you @MaVRoSCy .. i got it!! such a simple solution.. i wasnt thinking out of the box(integer values) only!!! thanks ;) – APPU cool Jun 14 '13 at 10:15

1 Answers1

0

first try with following thing way.. long phn = Integer.parseInt("12312312"); and also note this ....

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

It should be " ps.setString(6,uid);".

Tech_Harikishan
  • 123
  • 1
  • 7