• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Getting [java.lang.NumberFormatException: null] exception when sending data to another class

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to get the data from the client through servlet and sending it to another class method to perform query. But its getting  [java.lang.NumberFormatException: null] . I have printed the data I have got it is showing in the console and also printed the data after Integer.parseInt() it is also showing in the console. Even the data which passed to the another class method also printing in the console. But I am getting this exception.

Servlet code


Public Method Code

 
Marshal
Posts: 74376
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please indent your code correctly; the second code block isn't correctly indented and therefore difficult to read.
Where is the exception occurring? What text are you passing that causes the exception? I can't see anywhere where such an exception could be thrown in your code. Please post the stack trace and code with line numbers to match (see the middle of this link).
 
Ranch Hand
Posts: 179
2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I hope you doing well, I read what you've written above and I wish what I will say to you now going to help you

I would suggest writing a class that access your database using Connection Pool

1-create an XML file in META-INF/context.xml




2-, create a class named ConnectionPool that access your database via JNDI



3-, create a class that gets an object from your ConnectionPool class to perform CRUD operations





finally, create a helper class





Note that you must perform SQL operation inside the HTTP POST method instead of HTTP GET, HTTP POST method responsible to write data to your server unlike HTTP GET that reads data from your server
I used Connection Pool to gain performance while performing SQL operation, in addition, Apache Tomcat 7 later offers default connection pool, lib/tomcat-jdbc.jar, make this file available to your application and WEB-INF/lib
 
Campbell Ritchie
Marshal
Posts: 74376
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Useful code

Will that get rid of the number format exception? Do you really need all your methods static?
 
Houssam El
Ranch Hand
Posts: 179
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Useful code

Will that get rid of the number format exception? Do you really need all your methods static?



I've given a better way to perform CRUD operation on the database,
The error may have been thrown while parsing qid parameter



I think if he changes qid parameter to int the problem would get solved
 
Campbell Ritchie
Marshal
Posts: 74376
334
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you. I have added this discussion to the Servlets forum.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic