Results 1 to 3 of 3
  1. #1
    cypher_girl is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

    Default jsp insert into database error(java.lang.NumberFormatException: For input string: "")

    Hi all,

    I am trying to insert data from a jsp form into a table when the user clicks the submit button. I am encountering this exception.

    java.lang.NumberFormatException: For input string: "type"

    Here is my code:

    This is the code in the form jsp:

    <select name="utype">
    <% try
    {
    while(rs2.next())
    {
    int type=(rs2.getInt(1));
    String strName1=rs2.getString(2);
    %>
    <option value="type">
    <%= strName1 %>
    </option>
    <%
    }
    }
    catch(Exception e)
    {
    out.println(e);
    }

    %>
    </select>

    this is my code in the sign - up bean:

    db.connect();

    String firstName, lastName, address, city, state, email,userName, password, secAnswer;
    int zipcode, phoneNo, utype, squestion;

    firstName = request.getParameter( "firstName");
    lastName = request.getParameter( "lastName");
    address = request.getParameter( "address");
    city = request.getParameter( "city");
    state = request.getParameter( "state");
    zipcode = Integer.parseInt(request.getParameter( "zipcode"));
    email = request.getParameter( "email");
    phoneNo = Integer.parseInt(request.getParameter( "phoneNo"));
    userName = request.getParameter( "userName");
    password = request.getParameter( "password");
    utype = Integer.parseInt(request.getParameter( "utype"));
    squestion = Integer.parseInt(request.getParameter( "squestion"));
    secAnswer = request.getParameter( "secAnswer");

    db.insert(firstName, lastName, address, city, state, zipcode, email, phoneNo, userName, password, utype, squestion, secAnswer);
    response.sendRedirect("signupthanks.html");

    and this is my dbBean's insert method:

    public void insert(String firstName, String lastName, String address, String city, String state, int zipcode, String email, int phoneNo, String userName, String password,int utype, int squestion, String secAnswer) throws SQLException {
    try {

    PreparedStatement pstmt = null;
    String queryString =
    "INSERT INTO UserAccountDetails1(username,firstname, lastname, address, city, statecode, zipcode, email, phonenumber, password, usertypecode, questioncode, answer, lastmodifieduser, lastmodifiedtime) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

    pstmt = dbCon.prepareStatement(queryString);
    pstmt.setString(1, userName);
    pstmt.setString(2, firstName);
    pstmt.setString(3, lastName);
    pstmt.setString(4, address);
    pstmt.setString(5, city);
    pstmt.setString(6, state);
    pstmt.setInt(7, zipcode);
    pstmt.setString(8, email);
    pstmt.setInt(9, phoneNo);
    pstmt.setString(10, password);
    pstmt.setInt(11, utype);
    pstmt.setInt(12, squestion);
    pstmt.setString(13, secAnswer);
    pstmt.executeUpdate();
    pstmt.close();
    } catch (SQLException sqlex) {
    sqlex.printStackTrace();
    }
    }


    thank you very much. any help is greatly appreciated.:D

  2. #2
    luckacc is offline Member
    Join Date
    Nov 2008
    Posts
    8
    Rep Power
    0

    Default

    <option value="type">
    <%= strName1 %>
    </option>
    the value is 'type' ,not a int number,
    so when cast the utype to int ,it throws exception .

    utype = Integer.parseInt(request.getParameter( "utype"));
    correct code should be:
    <option value="<%= strName1 %>">
    <%= strName1 %>
    </option>[/
    Last edited by luckacc; 12-22-2009 at 03:10 AM.

  3. #3
    cypher_girl is offline Member
    Join Date
    Dec 2009
    Posts
    2
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 11-20-2009, 08:58 PM
  2. Replies: 3
    Last Post: 06-07-2009, 01:14 AM
  3. Replies: 3
    Last Post: 05-21-2009, 04:48 PM
  4. Hi , Error in Jsp page is as "NumberFormatException.forInputString(Unknown Source)"
    By lavanya82 in forum JavaServer Pages (JSP) and JSTL
    Replies: 9
    Last Post: 02-20-2009, 08:22 AM
  5. Replies: 1
    Last Post: 07-25-2007, 11:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •