tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robin Lee" <>
Subject Re: integer value
Date Mon, 25 Feb 2002 19:25:26 GMT
I assume that these fields are coming from a form from a previous page (ie:
html/jsp)...  And that you are submitting this information to a servlet, or
another jsp page.

One thing you are missing when testing for null is that, when coming from a
previous page, it may not be null, but BLANK (ie: "").  You need to test for
both ...

if (number == null || number.equals(""))
if (name == null || name.equals(""))

But because it is strictly a number, you need to convert the "number" field
to a pure integer # to test for a number.
int iNewNumber = Integer.parseInt(number);

Doing it this way allows you to make sure you don't have a null # because
Integer.parseInt will convert a "" string to a 0.

The code that has "number = 000000"; cannot happen because it is assumed
number is a String, and you can't convert int to String.

I hope this helps... You can email me directly if you need more help with

----- Original Message -----
From: "Uma Maheswar" <>
To: "Tomcat Users List" <>
Sent: Monday, February 25, 2002 9:31 AM
Subject: integer value

I have a doubt, I have a form that has name and his phone number, both
the fields are optional. I declared name as VARCHAR and number as
INTEGER in my SQL database. When the user leaves the fild empty, I get
an error with the number field as NumberFormatException.

So , What I need to do now is, when the user leaves the field null or
blank, I wanted to insert a default value into the database. For eg.

If(number == null)
    number = 000000;

I know the number if statement will give error.But could you please help
me with this?


To unsubscribe:   <>
For additional commands: <>
Troubles with the list: <>

View raw message