Results 1 to 10 of 10
  1. #1
    lavanya82 is offline Member
    Join Date
    Feb 2009
    Posts
    15
    Rep Power
    0

    Red face Hi , Error in Jsp page is as "NumberFormatException.forInputString(Unknown Source)"

    Hi,

    I am getting the following error "NumberFormatException.forInputString(Unknown Source)" in a JSP page.The Error is shown in the Integer.parseInt.
    i.e.
    <% b1=Integer.parseInt(request.getParameter("a1")); %>
    <% b2=Integer.parseInt(request.getParameter("a2")); %>


    Code:-

    <%@page import="javax.servlet.*"%>
    <%@page import="javax.servlet.http.*" %>
    <%@page import="java.sql.*" %>
    <%! Connection con; %>
    <%! Statement st; %>
    <%! ResultSet rs; %>
    <% int b1,b2,b11,b22,z=0; %>
    <% b1=Integer.parseInt(request.getParameter("a1")); %>
    <% b2=Integer.parseInt(request.getParameter("a2")); %>


    please help me with this.

  2. #2
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    what is request.getParameter("a1") and request.getParameter("a2") returning? Make sure it does not return null and any value which can't be converted to number.

  3. #3
    lavanya82 is offline Member
    Join Date
    Feb 2009
    Posts
    15
    Rep Power
    0

    Default

    Both the parameters "a1" and "a2" are used for table bank account number and balance from the table "bank" where they data type is intger/number.

  4. #4
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    request.getParameter method returns the value submitted through any html/jsp page, it has got nothing to do with database.

  5. #5
    lavanya82 is offline Member
    Join Date
    Feb 2009
    Posts
    15
    Rep Power
    0

    Default

    the request is been submitted here is from jsp page and the value which i am giving is account no. like 9841234345 and deposit number like 66.

  6. #6
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    9841234345 is causing the problem, its exceeding the range of int data type, so instead of storing it in int, store it in long, that might solve your problem, I assume that field a1 is returning this value so your code should be

    Java Code:
    <% int b2,b11,b22,z=0; %>
    <% long b1%>
    <% b1=Long.parseLong(request.getParameter("a1")); %>
    <% b2=Integer.parseInt(request.getParameter("a2")); %>

  7. #7
    lavanya82 is offline Member
    Join Date
    Feb 2009
    Posts
    15
    Rep Power
    0

    Default

    Hi,
    This is the full page code ... the exception problem is solved but i am not getting the desired output as "Account Updated."

    <%@page import="javax.servlet.*"%>
    <%@page import="javax.servlet.http.*" %>
    <%@page import="java.sql.*" %>
    <%! Connection con; %>
    <%! Statement st; %>
    <%! ResultSet rs; %>
    <% int b2,b11,b22,z=0;
    Long b1;%>
    <% b1=Long.parseLong(request.getParameter("a1")); %>
    <% b2=Integer.parseInt(request.getParameter("a2")); %>
    <% Class.forName("oracle.jdbc.driver.OracleDriver"); %>
    <% con=DriverManager.getConnection("jdbc:oracle:thin: @HDCHNVETA22270:1521:devdb","system","view123");
    st=con.createStatement();
    rs=st.executeQuery("select * from bank");
    try{
    while(rs.next()){

    b11=rs.getInt(2);

    if(b11==b1)
    {
    b22=rs.getInt(3);
    int s3=b22+b2;
    int k=st.executeUpdate("update bank set bal="+s3+" where accno="+b1+"");
    out.println("Account Updated.");
    }
    else
    z=1;
    }
    if(z==1)

    out.println("Account number does not exist");

    }
    catch(Exception e){
    System.out.print(e);

    }


    %>

  8. #8
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    Can you tell me the complete structure of the bank table, you are probably making the things bit more complicated.

  9. #9
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    If I got your requirement properly you are updating the balance based on any given account number, if that is the case the following code should work

    Java Code:
    <%@page import="javax.servlet.*"%>
    <%@page import="javax.servlet.http.*" %>
    <%@page import="java.sql.*" %>
    <%! Connection con; %>
    <%! Statement st1; %>
    <%! Statement st2; %>
    <%! ResultSet rs; %>
    <% int b2,b11,b22,z=0;
    Long b1;%>
    
    <% b1=Long.parseLong(request.getParameter("a1")); %>
    <% b2=Integer.parseInt(request.getParameter("a2")); %>
    <% Class.forName("oracle.jdbc.driver.OracleDriver"); %>
    <% con=DriverManager.getConnection("jdbcracle:thin: @HDCHNVETA22270:1521:devdb","system","view123");
    st=con.createStatement();
    rs=st.executeQuery("select * from bank where accno="+b1);
    try{
       if(rs.next()){
          b22=rs.getInt(3);
          int amountToUpdate=b22+b2;
          st1=con.createStatement();
          int updateCount=st1.executeUpdate("update bank set bal="+amountToUpdate+" where accno="+b1);
          if(updateCount>=1){
             out.println("Account Updated");
          }
          else{
             out.println("Failed To Update Account");
          }
          
       }
       else{
          out.println("No matching account number found in database");
       }
      }
      catch(Exception e){
      }
    %>
    However writing java codes inside jsp is not very recommended, we should write the java codes in side java classes and invoke those classes from jsp. jsp should just be used for the presentation logic.

  10. #10
    lavanya82 is offline Member
    Join Date
    Feb 2009
    Posts
    15
    Rep Power
    0

Similar Threads

  1. Replies: 2
    Last Post: 01-24-2009, 06:56 PM
  2. Replies: 0
    Last Post: 11-22-2008, 01:49 AM
  3. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  4. the web site "monitor test page"
    By dubdubdub in forum New To Java
    Replies: 0
    Last Post: 11-28-2007, 07:48 AM
  5. Strange error message "Source not found"
    By ppayal in forum Eclipse
    Replies: 0
    Last Post: 11-25-2007, 06:19 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
  •