• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java.lang.NumberFormatException: For input string: "16:30"

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want to insert time in the database using jsp, bean class and servlet. but i got the following error.
my html page

bean class:

insertdao.java:


in insertservlet:
 
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please post the exact stack trace which you get in console.
Tracing the bug becomes very easy once you learn to understand the stack trace.
 
deepak narahare
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Tapas Chand
26-Oct-2015 09:15:15.530 SEVERE [http-apr-8080-exec-39] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [insertservlet] in context with path [/example] threw exception
java.lang.NumberFormatException: For input string: "16:30"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
at java.lang.Long.parseLong(Long.java:589)
at java.lang.Long.parseLong(Long.java:631)
at insertservlet.processRequest(insertservlet.java:72)
at insertservlet.doPost(insertservlet.java:131)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2503)
at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2492)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Now from the stack trace, try to find which is the line of the code that causes the exception.
And then try to find the exact method in that line which causes the exception.

hint: Find the place where stack trace transfers to Java's built in class from your class.
 
deepak narahare
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Tapas Chand
I know in this line the error is coming in Insertservlet


but I don't know how to resolve it.
 
Tapas Chand
Ranch Hand
Posts: 624
9
BSD Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good.
Now there are 2 places in this line where the exception can occur.
1. new Time()
2. Long.parseLong()

If you have a good look at the stack trace, there something like
It says exception occurs when Java is trying to convert String "16:30" to Long.
You must pass a String having all numeric values to parseLong() method otherwise it will throw exception.

Regarding the resolution, I always prefer passing "String" from JDBC and convert the "String" into Date datatype in the query itself. This simplifies my Java code
e.g.


Few more things to remember
  • By Java naming convention, class name should be start with Uppercase. So change "insertdao" to "InsertDao" and "insertservlet" to "InsertServlet".
  • If you have called processRequest() from both doGet() and doPost(), avoid that. The two methods are there for two different purpose.

  •  
    deepak narahare
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    @Tapas chand thanks for the help let me try and I'll let you know weather i got the answer or not
     
    deepak narahare
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    @Tapas Chand thanksalot man, it worked!! But the problem is I want to add the both the times(logintime and logouttime)... by passing "String" from JDBC and convert the "String" into Date datatype in the query will help in calculating those logintime and logouttime and it must diosplay on jsp/ html page...if so please tell me how to do this thing
     
    Tapas Chand
    Ranch Hand
    Posts: 624
    9
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Not able to get the requirement actually.
    Can you explain a bit what exactly you want to display in browser?

    If you want to display something like this,
    then a simple select query will do.
     
    deepak narahare
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I want to enter to values in two input box. then the total must come in the third box automatically in the same page
     
    Tapas Chand
    Ranch Hand
    Posts: 624
    9
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    There are 2 scenarios.

    1. You enter the values in 2 textboxes, calculate and display result in 3rd textbox.
    Then insert values in DB.
    In this case there is no need to go to DB for the calculation. It can be done in JavaScript itself.

    2. You enter the values in 2 textboxes, insert the values in DB. Then display the calculation result in 3rd textbox.
    In this case calculation can be done either in JavaScript, in Java or in DB.

    Which is your scenario?
     
    deepak narahare
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    @Tapas Chand
    thanks for the reply... I want first scenario.
     
    Tapas Chand
    Ranch Hand
    Posts: 624
    9
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Then I guess this post should be moved to JavaScript: How to calculate time difference.
    You can search for some already created functions to get time difference.
     
    deepak narahare
    Greenhorn
    Posts: 21
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    alright... thanks alot for helping me!!
     
    Sheriff
    Posts: 67746
    173
    Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Tapas Chand wrote:Then I guess this post should be moved to JavaScript: How to calculate time difference.


    As this post is long and the original topic is a rather different than this new direction, I think a new post in the JavaScript forum detailing the issue should be made, rather than moving this one.
     
    Tapas Chand
    Ranch Hand
    Posts: 624
    9
    BSD Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    Bear Bibeault wrote:As this post is long and the original topic is a rather different than this new direction, I think a new post in the JavaScript forum detailing the issue should be made, rather than moving this one.


    Yes Bear, you seem right. A fresh thread will be cleaner and better.
    reply
      Bookmark Topic Watch Topic
    • New Topic