title: NumberFormatException for a value in jsp
body: <p>I am passing value from JSP to a java class to store it in Database. It is giving NumberFormatException for the <code>Contact No.</code> value in Jsp. I am not able to figure out why is this happening. The parsing in the java class from string to integer somehow fails for <code>Contact No.</code> value which is passed from Jsp to Java class.</p>
  
  <p>JSP</p>
  
  <pre><code>&lt;%@page import="register.register"%&gt;
  
  &lt;%@page contentType="text/html" pageEncoding="UTF-8"%&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="content-type" content="text/html; charset=utf-8" /&gt;
  &lt;title&gt;PenguinSoft(India)&lt;/title&gt;
  &lt;meta name="keywords" content="" /&gt;
  &lt;meta name="description" content="" /&gt;
  &lt;link href="default.css" rel="stylesheet" type="text/css" /&gt;
  &lt;/head&gt;
  &lt;body&gt;
       &lt;%
  
  
  
                          String stdname = request.getParameter("student");
                          String batch = request.getParameter("batch");
                                                  String email = request.getParameter("email");
                                                  String contact = request.getParameter("contact");
                                                  String fees=request.getParameter("fees");
                          if(stdname!=null &amp;&amp; batch!=null &amp;&amp; email!=null &amp;&amp; contact!=null &amp;&amp; fees!=null)
                                                  {
  
                              register objadd = new register();
                              boolean flag=objadd.InsertNew(stdname,batch,email,contact,fees);
                              if(flag)
                                                          {
                                                              System.out.println("Yes");
                                                          }
                                                  }       
  
                      %&gt;
  &lt;form action="Register.jsp" method="POST"&gt;
  
  &lt;div id="header"&gt;
      &lt;div id="logo"&gt;
          &lt;h1&gt;&lt;a href="#"&gt;&lt;/a&gt;&lt;/h1&gt;
          &lt;h3&gt;&lt;a href="#"&gt;PenguinSoft&lt;/a&gt;&lt;/h3&gt;
      &lt;/div&gt;
      &lt;div id="menu"&gt;
          &lt;ul&gt;
              &lt;li class="first"&gt;&lt;a href="#" title=""&gt;New Batch&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="Login.jsp" title=""&gt;Register Student&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="AddEmployeeData.jsp" title=""&gt;Fees Record&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="AddKeywords.jsp" title=""&gt;Manage Student&lt;/a&gt;&lt;/li&gt;
              &lt;li&gt;&lt;a href="StopWordDetectionForm.jsp" title=""&gt;All Details&lt;/a&gt;&lt;/li&gt;
          &lt;/ul&gt;
      &lt;/div&gt;
      &lt;div id="ad468x60"&gt;&lt;a href="#"&gt;&lt;img src="images/spam1.gif" alt="" width="468" height="60" /&gt;&lt;/a&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div id="page"&gt;
      &lt;div id="content"&gt;
          &lt;div class="boxed"&gt;
              &lt;h1 class="heading"&gt;Welcome to SPAM Management&lt;/h1&gt;
              &lt;div class="content"&gt;
                  &lt;img src="images/no-spam-2x.gif" alt="" width="122" height="123" class="left" /&gt;
                  &lt;p&gt;&lt;/p&gt;
                  &lt;p&gt;&lt;/p&gt;
  
  
  
  &lt;blockquote&gt;
  
  
  &lt;p align="left"&gt;&lt;font size="3"&gt;Student Name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &lt;/font&gt;
  &lt;input type="text" name="student" size="26" style="font-family: Tahoma; font-size: 10pt" onBlur="return one(this.form)"/&gt;&lt;/p&gt;
  &lt;p align="left"&gt;&lt;font size="3"&gt;Batch&lt;select name="batch"&gt;
              &lt;option&gt;Java&lt;/option&gt;
              &lt;option&gt;PHP&lt;/option&gt;
              &lt;option&gt;Framework&lt;/option&gt;
              &lt;option&gt;Android&lt;/option&gt;
              &lt;/select&gt;
  &lt;/font&gt;
  &lt;/p&gt;
  &lt;p align="left"&gt;&lt;font size="3"&gt;Email ID&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &lt;/font&gt;
  &lt;input type="text" name="email" size="26" style="font-family: Tahoma; font-size: 10pt" onBlur="return one(this.form)"/&gt;&lt;/p&gt;
  &lt;p align="left"&gt;&lt;font size="3"&gt;Contact No.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &lt;/font&gt;
  &lt;input type="text" name="contact" size="26" style="font-family: Tahoma; font-size: 10pt" onBlur="return one(this.form)"/&gt;&lt;/p&gt;
   &lt;p align="left"&gt;&lt;font size="3"&gt;Fees&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
  &lt;/font&gt;
  &lt;input type="text" name="fees" size="26" style="font-family: Tahoma; font-size: 10pt" onBlur="return one(this.form)"/&gt;&lt;/p&gt;   
  &lt;p align="left"&gt;
  &lt;/p&gt;&lt;br&gt;
  &lt;input type="submit" value="Register Student"name="submit" align="center"/&gt;
  
  &lt;/form&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;!-- end #content --&gt;
      &lt;div id="sidebar"&gt;
          &lt;div class="boxed"&gt;
              &lt;h2 class="heading"&gt;Key Features: &lt;/h2&gt;
              &lt;div class="content"&gt;
                  &lt;ul&gt;
                      &lt;li&gt;PenguinSoft(India) is one of the major leading training institute in Software Development in India.&lt;/li&gt;
                      &lt;li&gt;Training provided in Java,PHP,Android,database,etc&lt;/li&gt;
                      &lt;li&gt;Live project development is also provided&lt;/li&gt;
                  &lt;/ul&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;!-- end #sidebar --&gt;
  &lt;/div&gt;
  &lt;!-- end #page --&gt;
  &lt;div style="clear: both;"&gt;&amp;nbsp;&lt;/div&gt;
  &lt;div id="footer"&gt;
      &lt;p id="legal"&gt;Copyright &amp;copy; PenguinSoft(India) All Rights Reserved.&lt;/p&gt;
      &lt;p id="links"&gt;&lt;a href="#"&gt;Privacy Policy&lt;/a&gt; | &lt;a href="#"&gt;Terms of Use&lt;/a&gt;&lt;/p&gt;*/
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Java class</p>
  
  <pre><code>package register;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  
  /*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  
  /**
   *
   * @author asus
   */
  public class register {
  
  
      public boolean InsertNew(String stdname,String stdbatch,String email,String contact,String fees){
            boolean flag = false;
            Connection con = null;
            String connectionURL = "jdbc:mysql://localhost:3306/penguinsoft";
  
          Connection connection = null;
          ResultSet rs;       
  
          try {
              // Load the database driver
              Class.forName("com.mysql.jdbc.Driver");
              // Get a Connection to the database
              connection = DriverManager.getConnection(connectionURL, "root", "");
              //Add the data into the database
  
              //String sql = "insert into sample values(?,?)";
               int stdcontact=Integer.parseInt(contact);
                  int stdfees=Integer.parseInt(fees);
              PreparedStatement pst = connection.prepareStatement("INSERT into alldetails VALUES(?,?,?,?,?,?)");
  
              pst.setString(1,null);
              pst.setString(2,stdname);
              pst.setString(3,email);
              pst.setInt(4,stdcontact);
              pst.setString(5,stdbatch);
              pst.setInt(6,stdfees);
  
  
              int numRowsChanged = pst.executeUpdate();
              if(numRowsChanged!=0){
                  System.err.println("Successfull execution");
              }
              else{
                              System.err.println("Problem with the insertion query");
              }
              pst.close();
              }
              catch(ClassNotFoundException e){
                              e.printStackTrace();
              }
              catch(SQLException e){
                              e.printStackTrace();
              }
                  catch(NumberFormatException nfe)
                  {
                      nfe.printStackTrace();
                  }
              catch (Exception e){
                              e.printStackTrace();
              }
  
              finally {
              // Always close the database connection.
              try {
              if (connection != null) connection.close();
              }
              catch (SQLException ignored){
              }
              }
  
             return true;
           }   
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>java.lang.NumberFormatException: For input string: "12345678"
      at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
      at java.lang.Integer.parseInt(Integer.java:495)
      at java.lang.Integer.parseInt(Integer.java:527)
      at register.register.InsertNew(register.java:37)
      at org.apache.jsp.Register_jsp._jspService(Register_jsp.java:89)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
      at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
      at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
      at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
      at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
      at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
      at java.lang.Thread.run(Thread.java:744)
  </code></pre>