473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

about NumberFormatException

Hello to all,
I have a problem about NumberFormatException and i m very sad because i m not able to solve this.
So please help.

The code is----------
Expand|Select|Wrap|Line Numbers
  1. <code>
  2.  
  3.  
  4.  
  5. <%@page import="Connection.Connect" %>
  6. <%@page import="java.sql.*" %>   <%-- for SQL Statements--%>
  7. <%@page import="java.util.*" %>
  8. <%@page import="java.math.BigInteger"%>
  9. <%@page import="java.math.*" %>
  10. <html>
  11.     <head>
  12.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  13.         <title>credit report</title>
  14.     </head>
  15.     <body>
  16.         <form action="Logout.jsp" name="Submit" method="POST">
  17.              <table border="0" cellspacing="0" width="100%">
  18.                 <tbody>
  19.                      <tr>
  20.  
  21.  
  22.                         <td><font size="8"><b>Automatic tailer System</b></font></td>
  23.  
  24.                          <td align="right"><input type="submit" value="LOGOUT" name="LGB" /></td>
  25.  
  26.                      </tr>
  27.  
  28.                  </tbody>
  29.              </table>
  30.          </form>
  31.  
  32.  
  33.         <div align="center" style=" background-color: black ">
  34.             <font color="white"><b>Employee ID : </b><%= session.getAttribute("ID") %> </font> &nbsp;&nbsp;&nbsp;&nbsp;
  35.             <font color="white"><b>Branch : </b> <%= session.getAttribute("branch") %></font> &nbsp;&nbsp;&nbsp;&nbsp;
  36.         </div>
  37.  
  38.         <%
  39.  
  40.              String ID2=session.getAttribute("ID2").toString().trim();
  41.              String name=session.getAttribute("name").toString().trim();
  42.              String am=request.getParameter("amount").trim();
  43.              int amt=Integer.parseInt(am);
  44.              String cred=request.getParameter("credited").trim();
  45.  
  46. try
  47.     {
  48.         Connection con3=null;
  49.         String statement3="Select * from MASTER where ID = '" + ID2 + "'";
  50.         Connect newconn3 = new Connect();
  51.         ResultSet result3=null;
  52.         Statement command3 = null;
  53.         con3 = newconn3.create();
  54.         command3 = con3.createStatement();
  55.         result3 = command3.executeQuery(statement3);
  56.         result3.next();
  57.        String IDreq = result3.getString("ID").trim();
  58.         String acc_t= result3.getString("ACCOUNT_TYPE").trim();
  59.        int tb=result3.getInt("TOTAL_BAL");
  60.         tb=tb+amt;
  61.  
  62.  
  63.  
  64.  
  65.        String Cr;
  66.  
  67.  
  68.             Connection con=null;
  69.             String getreq="SELECT MAX(TRAN_ID) FROM CREDIT";
  70.             Connect newconn = new Connect();
  71.             ResultSet result=null;
  72.             Statement command = null;
  73.             con = newconn.create();
  74.             command = con.createStatement();
  75.             result = command.executeQuery(getreq);
  76.             result.next();
  77.             String find = String.valueOf(result.getBigDecimal(1));
  78.  
  79.             String nextreqcom="";
  80.             int request_id;
  81.             java.util.Date curr = new java.util.Date();
  82.  
  83.             int cyear = curr.getYear()+1900;
  84.             int cdate = curr.getDate();
  85.             int cmonth = curr.getMonth()+1;
  86.  
  87.            if((find.length()==4)||(find.equals(null)))
  88.             {
  89.                 find="000001";
  90.                 if(cmonth<10)
  91.                 {
  92.                     nextreqcom = cyear+"0"+cmonth+""+cdate+""+find;
  93.                 }
  94.                 if(cdate<10)
  95.                 {
  96.                     nextreqcom = cyear+""+cmonth+"0"+cdate+""+find;
  97.                 }
  98.                 if((cmonth<10)&&(cdate<10))
  99.                 {
  100.                     nextreqcom = cyear+"0"+cmonth+"0"+cdate+""+find;
  101.                 }
  102.                request_id =Integer.parseInt((nextreqcom).trim());
  103.               // request_id = new BigInteger(nextreqcom);
  104.             }
  105.            else
  106.             {
  107.  
  108.  
  109.  
  110.                 int maxreq = Integer.parseInt(find.substring(8));
  111.                 int nextreq=maxreq+1;
  112.  
  113.                 String chk = String.valueOf(nextreq);
  114.                 String valuereq="";
  115.                 switch(chk.length())
  116.                 {
  117.                     case 1 : valuereq = "00000"+nextreq;
  118.                     break;
  119.                     case 2 : valuereq = "0000"+nextreq;
  120.                     break;
  121.                     case 3 : valuereq = "000"+nextreq;
  122.                     break;
  123.                     case 4 : valuereq = "00"+nextreq;
  124.                     break;
  125.                     case 5 : valuereq = "0"+nextreq;
  126.                     break;
  127.                     case 6 : valuereq = ""+nextreq;
  128.                     break;
  129.  
  130.                 }
  131.                 if(cmonth<10)
  132.                 {
  133.                     nextreqcom = cyear+"0"+cmonth+""+cdate+""+valuereq;
  134.                 }
  135.                 if(cdate<10)
  136.                 {
  137.                     nextreqcom = cyear+""+cmonth+"0"+cdate+""+valuereq;
  138.                 }
  139.                 if((cmonth<10)&&(cdate<10))
  140.                 {
  141.                     nextreqcom = cyear+"0"+cmonth+"0"+cdate+""+valuereq;
  142.                 }
  143.                request_id =Integer.parseInt((nextreqcom).trim());
  144.                //  request_id = new BigInteger(nextreqcom);
  145.  
  146.             }
  147.  
  148.             java.util.Date ff = new java.util.Date();
  149.             int mm = ff.getMonth()+1;
  150.             int dd = ff.getDate();
  151.             int yyyy = ff.getYear()+1900;
  152.             String today = yyyy+"-"+mm+"-"+dd;
  153.  
  154.              Connection con2 = newconn.create();
  155.             Statement command2 = con2.createStatement();
  156.             String insert = "INSERT INTO CREDIT(TRAN_ID,ID,NAME,ACCOUNT_TYPE,AMOUNT,CREDITED_BY,TOTAL_BAL,CURT,TRAN_TYPE) values('"+request_id+"','"+IDreq+"','"+name+"','"+acc_t+"','"+amt+"','"+cred+"','"+tb+"','"+today+"','Cr')";
  157.             int set = command2.executeUpdate(insert);
  158.             String show = "REQV"+request_id;
  159.  
  160.  
  161.  
  162.             Connection con1=null;
  163.             con1 = newconn.create();
  164.             Statement command1 = con1.createStatement();
  165.              String update = "UPDATE MASTER SET TOTAL_BAL='"+tb+"' WHERE ID='"+IDreq+"'";
  166.             int set1 = command1.executeUpdate(update);
  167.         %>
  168.  
  169.          <BR>
  170.         <fieldset><legend><font face="Verdana" size="5">SYSTEM REPORT</font></legend>
  171.  
  172.  
  173. <table border=0 width=100% height=100%><tr><td>
  174.  
  175. <table width=50%>
  176. <tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr>
  177. <tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr>
  178. <tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr>
  179. <tr><td align="center"><font face="Courier" size="3">The amount is credited in respective account.</font></td></tr>
  180.  
  181.  
  182. <tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr>
  183. <tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr>
  184. <tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr>
  185.  
  186. <tr><td align="center"><font face="Courier" size="3">Transaction ID is: <b><%=show%></b></font></td></tr>
  187.  
  188. <tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr>
  189. <tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr>
  190. <tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr><tr><td></td></tr>
  191. </table>
  192.  
  193.  
  194. </td></tr></table>
  195.         </fieldset>
  196.  
  197. <BR>
  198. <form name="Employee" action="Employee.jsp" method="POST">
  199.     <div style="width:100%">
  200. <table style="width:100%">
  201. <tr>
  202. <td align="center" style="width:20%"><input style="width:20%" type="submit" value="OK" name="ID"></td>
  203. </tr>
  204. </table>
  205.     </div>
  206. </form>
  207.  
  208.  
  209.         <%
  210.  
  211.          }
  212.     catch(Exception e)
  213.             { %> <%=e.toString() %>
  214.  
  215.            <%
  216.     }
  217.          %>
  218.     </body>
  219. </html>
  220.  
  221.  
  222. </code>
  223.  
and error is ----

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


Thanks in advance.
Aug 19 '10 #1

✓ answered by om anand giri

Respected Sir,
Thanks for your suggestions.
I have solved my problem and these codes work properly.
In future i am always ask for your help.So please help me if i want in future.

Thanks.

7 3066
chaarmann
785 Expert 512MB
The number is too big to fit into an integer.

"System.out.println(Integer.MAX_VALUE);" will give you 2147483647. Because it is a 32 bit signed type.

You can use class java.math.BigInteger to store bigger numbers.

By the way, I can't see which statement caused the error. You only listed the jsp-code. Please list the corresponding Java-code (remember: jasper of Tomcat compiles every jsp-page into class-files and puts the corresponding java-code in a special directory. For example by default, "test.jsp" would generate "test_jsp.java" Just grab it from there and list it here, together with the line number where the error happened.
And most important, please use code-tags around your code this time when you list it here!
Aug 20 '10 #2
Dheeraj Joshi
1,123 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. 20100819000001
  2.  
It looks like date to me 2010 08 19 00 00 01. What you want to do with it?
If you want to convert this into an integer, you can't convert. See chaarmann's post.

Can you post the section of code which give this error? And please use code tag while posting.

Regards
Dheeraj Joshi
Aug 20 '10 #3
sir,
i m alredy used class biginteger.
but my problem is not solved.
I m using glassfish derby server and javadb.
I am doing project on ATM web application, and when a customer credit money in his account then a reference id is generated. this is that number that is a unique number.
i m able to generate this but i m not able to save this in database.
i m using datatype bigint in javadb.
but this exception is generated and value is not going to database.
if u have any other idea or code then please send it to me. i m not understand, where that file allocated which u want.
Sir, please hepl me abut this.
How can i generate this number because the desired id format is same as given.

Thanks.
Aug 20 '10 #4
chaarmann
785 Expert 512MB
You wrote "i m alredy used class biginteger". That's right, but it's commented out in the code above. So it's not currently used. What is the problem if you use it? You shouldn't get a NumberFormatException if you use it, so maybe the error happens somewhere else where you don't use it, but should do.

You wrote "i m not understand, where that file allocated which u want."
Please look in your tomcat-work-directory. The direct path depends where you installed Tomcat. My tomcat installation is in "C:\Program Files\ApacheTomcat". You will find some directories named "bin" (executable of tomcat), "logs" (your logs) "webapps" (where your jsp-files are) and also "work". In subdirectory "Catalina\localhost\_" (Yes, the directory name is an underscore) of your "work"-directory is all the java-code located that tomcat generated. Here you will find the java-file that corresponds to the jsp-file you listed above. If you can't find it there, then search one directory higher by application name ("Catalina\localhost\(myApplication)". If you can't find it there, the search the whole work-directory, listing all files by date. The wanted file is the one which was just gererated, that means with the latest date.
Please remember to use code tags if you list this java code here, along with the error-line number from the log.

You wrote "Sir, please hepl me abut this."
In order to help you, it is very important to know the line number where the error happened. This also will help you much in your own future error analysis.
So if you still have problems to grab the file and line of error, then rewrite your code.
You have to rewrite it anyway, because you are not following MVC coding standard and it will never pass QA: Your jsp-page should only contain the view-logic (html-commands) and not the business-logic (database access). You must put all your business-logic into a Java Action-class (if using Struts) or into a java-servlet. And if you compile that java-servlet manually, the compiler right away will give you the line number and error.

By the way, your code:
Expand|Select|Wrap|Line Numbers
  1. String chk = String.valueOf(nextreq);
  2. String valuereq="";
  3. switch(chk.length())
  4. {
  5. case 1 : valuereq = "00000"+nextreq;
  6. break;
  7. case 2 : valuereq = "0000"+nextreq;
  8. break;
  9. case 3 : valuereq = "000"+nextreq;
  10. break;
  11. case 4 : valuereq = "00"+nextreq;
  12. break;
  13. case 5 : valuereq = "0"+nextreq;
  14. break;
  15. case 6 : valuereq = ""+nextreq;
  16. break;
could be simply rewritten as:
Expand|Select|Wrap|Line Numbers
  1. final String leadingZeros = "000000";
  2. String valuereq = leadingZeros + nextreq;
  3. valuereq = valuereq.substring(valuereq.length() - leadingZeros.length());
Aug 23 '10 #5
Respected Sir,
Thanks for your suggestions.
I have solved my problem and these codes work properly.
In future i am always ask for your help.So please help me if i want in future.

Thanks.
Aug 24 '10 #6
Sir,
I have a new problem.
Actually i was design this code to handle the reference number and i want it to reset when date is changed.
As at present date it is "CR20100824000007" and at next day it is "CR20100825000008".
But i want it as "CR20100825000001".
How could it possible by this code?
Please help me about this new problem.
Attached Files
File Type: txt credit_rpt.txt (7.0 KB, 454 views)
Aug 24 '10 #7
chaarmann
785 Expert 512MB
Can you please tell us what was the exact problem at last and how you have solved your problem? In listing your properly working code or your solution here, that means sharing your knowledge, many other readers will benefit from the solution, in the same way you benefited from the knowledge I shared.

Also please open a new thread for your new problem, and don't put the source code as attachment, instead paste it directly and wrap code-tags around it (just select the whole code and use the #-button of the message-editor)
Aug 24 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
8
by: eScrewDotCom | last post by:
eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is very funny. eScrew...
0
by: Joe | last post by:
Hi, I am trying to connect to a MySQL database through a Java Servlet. I think I have correctly installed Tomcat 4.1.30 and the MySQL Database along with ConnectorJ. I am getting a...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
5
by: eScrewDotCom | last post by:
www.eScrew.com eScrew Welcome to eScrew! eScrew is eScrew and this is eScrew story. eScrew will tell you eScrew story if you promise eScrew to consider eScrew story as joke. eScrew story is...
3
by: jackyustb | last post by:
code as following ... String s1=Integer.toBinaryString(-1073741824) System.out.println(s1); int i2=Integer.parseInt(s1,2); ... the output is ... 11000000000000000000000000000000...
3
by: satyakarvvk | last post by:
Hi everybody! Please help me to overcome below runtime exception. Actually it is a simple program on basics. I want to print odd nos upto which the user asks and after printing the task,...
1
by: prasanna ganesh | last post by:
why i'm getting lang.string.NumberFormatException for input string ""please help me to find solution
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.