Problem in converting string into int!

Discussions

Web tier: servlets, JSP, Web frameworks: Problem in converting string into int!

  1. Problem in converting string into int! (2 messages)

    Hi, I have trouble in converting string values which I get from a form and convert to int and then store it into MS sql server 2000.
    I use the following code:
    String fcHPEComp3s = request.getParameter("fcHPEComp3");
    int cHPEComp3 = Integer.parseInt(fcHPEComp3s);
    fcHPEComp3 is the exact name of the input value and cHPEComp3 is the exact name of the database column. The wired thing is the code works for other variables, but not for this one. I got an NumberFormatException error message(Error 500). The code, the variable name, and everything is correct. Otherwise, other variables shouldn't work. I use tomcat on win 2k server to handle java. Thank you for any of your help.

  2. Hi Yong
    Why don't u catch an Exception like below
    int cHPEComp3=0;
    try
    {
    cHPEComp3 = Integer.parseInt(request.getParameter("fcHPEComp3s"));
    out.println("value="+cHPEComp3);
    }
    catch(NumberFormatException e)
    {
    out.println("value="+cHPEComp3);
    }
  3. If the value "null" comes, you will get the exception.
    Please check if the value is null.
    Otherwise you can put your code in try catch block and find out what exactly is comming through the request object.

    I suspect you are getting a null.
    Please verify.