Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-19-2009, 01:29 PM
Member
 
Join Date: Feb 2009
Posts: 15
Rep Power: 0
lavanya82 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 02-19-2009, 01:58 PM
Senior Member
 
Join Date: Dec 2008
Posts: 164
Rep Power: 2
dswastik is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-19-2009, 02:26 PM
Member
 
Join Date: Feb 2009
Posts: 15
Rep Power: 0
lavanya82 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-19-2009, 02:29 PM
Senior Member
 
Join Date: Dec 2008
Posts: 164
Rep Power: 2
dswastik is on a distinguished road
Default
request.getParameter method returns the value submitted through any html/jsp page, it has got nothing to do with database.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-19-2009, 02:36 PM
Member
 
Join Date: Feb 2009
Posts: 15
Rep Power: 0
lavanya82 is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 02-19-2009, 02:43 PM
Senior Member
 
Join Date: Dec 2008
Posts: 164
Rep Power: 2
dswastik is on a distinguished road
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

Code:
<% int b2,b11,b22,z=0; %>
<% long b1%>
<% b1=Long.parseLong(request.getParameter("a1")); %>
<% b2=Integer.parseInt(request.getParameter("a2")); %>
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 02-19-2009, 03:02 PM
Member
 
Join Date: Feb 2009
Posts: 15
Rep Power: 0
lavanya82 is on a distinguished road
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("jdbcracle: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);

}


%>
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 02-19-2009, 03:06 PM
Senior Member
 
Join Date: Dec 2008
Posts: 164
Rep Power: 2
dswastik is on a distinguished road
Default
Can you tell me the complete structure of the bank table, you are probably making the things bit more complicated.
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 02-19-2009, 03:20 PM
Senior Member
 
Join Date: Dec 2008
Posts: 164
Rep Power: 2
dswastik is on a distinguished road
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

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.
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 02-20-2009, 08:22 AM
Member
 
Join Date: Feb 2009
Posts: 15
Rep Power: 0
lavanya82 is on a distinguished road
Default
Thks for the help the problem is solved
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan") soc86 New To Java 2 01-24-2009 07:56 PM
"source not found" at debug time when creating new class rafamd11 New To Java 0 11-22-2008 02:49 AM
the dollar sign "$", prints like any other normal char in java like "a" or "*" ? lse123 New To Java 1 10-20-2008 08:35 AM
the web site "monitor test page" dubdubdub New To Java 0 11-28-2007 08:48 AM
Strange error message "Source not found" ppayal Eclipse 0 11-25-2007 07:19 PM


All times are GMT +2. The time now is 08:18 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org