• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

handling null numeric fields

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Marshal
Posts: 67463
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Nothing? Or something? Like this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic