• Post Reply Bookmark Topic Watch Topic
  • New Topic

handling null numeric fields

 
B Bruford
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.
 
Eric Pascarello
author
Rancher
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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
108
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
Manfred Leonhardt
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!