Results 1 to 10 of 10
- 02-19-2009, 12:29 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 15
- Rep Power
- 0
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.
- 02-19-2009, 12:58 PM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
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.
- 02-19-2009, 01:26 PM #3
Member
- Join Date
- Feb 2009
- Posts
- 15
- Rep Power
- 0
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.
- 02-19-2009, 01:29 PM #4
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
request.getParameter method returns the value submitted through any html/jsp page, it has got nothing to do with database.
- 02-19-2009, 01:36 PM #5
Member
- Join Date
- Feb 2009
- Posts
- 15
- Rep Power
- 0
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.
- 02-19-2009, 01:43 PM #6
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
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")); %>
- 02-19-2009, 02:02 PM #7
Member
- Join Date
- Feb 2009
- Posts
- 15
- Rep Power
- 0
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);
}
%>
- 02-19-2009, 02:06 PM #8
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
Can you tell me the complete structure of the bank table, you are probably making the things bit more complicated.
- 02-19-2009, 02:20 PM #9
Senior Member
- Join Date
- Dec 2008
- Location
- Kolkata
- Posts
- 280
- Rep Power
- 5
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
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.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){ } %>
- 02-20-2009, 07:22 AM #10
Member
- Join Date
- Feb 2009
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
"source not found" at debug time when creating new class
By rafamd11 in forum New To JavaReplies: 0Last Post: 11-22-2008, 01:49 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM -
the web site "monitor test page"
By dubdubdub in forum New To JavaReplies: 0Last Post: 11-28-2007, 07:48 AM -
Strange error message "Source not found"
By ppayal in forum EclipseReplies: 0Last Post: 11-25-2007, 06:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks