You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Uma Maheswar <he...@globalleafs.com> on 2002/02/25 17:31:36 UTC
integer value
Hi,
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;
}
if(name==null)
{
name="tomcat";
}
I know the number if statement will give error.But could you please help me with this?
Uma
Re: integer value
Posted by Robin Lee <te...@uls.com>.
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(""))
OR
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
this.
...Robin
----- Original Message -----
From: "Uma Maheswar" <he...@globalleafs.com>
To: "Tomcat Users List" <to...@jakarta.apache.org>
Sent: Monday, February 25, 2002 9:31 AM
Subject: integer value
Hi,
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;
}
if(name==null)
{
name="tomcat";
}
I know the number if statement will give error.But could you please help
me with this?
Uma
--
To unsubscribe: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>
RE: integer value
Posted by Jim Urban <ji...@netsteps.net>.
Why did you declare a phone number as integer? I've seen phone numbers
declared as char 10 (unformatted), char 14 (formatted) or even varchar, but
never integer. If you use a char type field you can define the field as
null able too, which solves your problem.
Jim
> -----Original Message-----
> From: Uma Maheswar [mailto:help@globalleafs.com]
> Sent: Monday, February 25, 2002 10:32 AM
> To: Tomcat Users List
> Subject: integer value
>
>
> Hi,
> 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;
> }
> if(name==null)
> {
> name="tomcat";
> }
>
> I know the number if statement will give error.But could you
> please help me with this?
>
> Uma
>
--
To unsubscribe: <ma...@jakarta.apache.org>
For additional commands: <ma...@jakarta.apache.org>
Troubles with the list: <ma...@jakarta.apache.org>