• 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

handling null numeric fields

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an HTML form in which I have text boxes, text areas, radio buttons , and checkboxes. I am getting form data and putting it into an Oracle database using preparedStatement.
All of the fields may not be filled out so I am using this for string fields:
<req:existsParameter name="supervisor">
<%supervisor = (request.getParameter("supervisor"));
%>
</req:existsParameter>
which works. And for numeric fields (coming from the radio buttons and checkboxes) I am using this:
<req:existsParameter name="training">
<%training = new Integer(request.getParameter("training"));
%>
</req:existsParameter>
If any of the numeric fields are blank I get:
Error: java.lang.NullPointerException

any help in this problem would be greatly appreciated.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A solution on the SQL query is to look into ISNULL, not sure what to do on the jsp side since I know very little.
Eric
 
Sheriff
Posts: 67747
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
Can't really help you out without more of the stack trace, and the code snippet showing the line where the NPE occurs.
bear
P.S. Please use the UBB code tags for any included code.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
B,
Since Integer in java is immutable you must create it with a non-null value. There is no empty constructor. It also chokes on an empty String sent into the Integer constructor that accepts Strings.
Therefore, you must see if the request parameter exists, is not null, and has some length before you just use it.
Regards,
Manfred.
 
reply
    Bookmark Topic Watch Topic
  • New Topic