Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

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

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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


  2. #2
    Junior Member
    Join Date
    Jan 2010
    Posts
    6
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    I think <option value="type"> should <option value="<%=type%>">

Similar Threads

  1. Replies: 16
    Last Post: August 27th, 2010, 03:30 PM
  2. Please help! Exception in thread "main" java.lang.NullPointerException
    By Arutha2321 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 18th, 2009, 02:25 AM
  3. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM
  4. Replies: 1
    Last Post: October 25th, 2009, 11:54 AM
  5. Getting "AWT-EventQueue-0" java.lang.NullPointerException error
    By tryingtoJava in forum AWT / Java Swing
    Replies: 9
    Last Post: September 21st, 2009, 10:46 PM