RE: integer value

2002-02-25 Thread Jim Urban

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:[EMAIL PROTECTED]]
 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 = 00;
 }
 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:   mailto:[EMAIL PROTECTED]
For additional commands: mailto:[EMAIL PROTECTED]
Troubles with the list: mailto:[EMAIL PROTECTED]




RE: integer value

2002-02-25 Thread Justin Rowles

 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. 

If you really want to do it this way, you can catch the exception (see a book on Java) 
and set it there.

Better still, don't try to force the data into an integer field, cos it isn't really.  
You can check that it is only made of certain characters (0-9) instead.

J.
-- 
You're only jealous cos the little penguins are talking to me. 



***
For more information on Ordnance Survey products and services,
visit our web site at http://www.ordnancesurvey.co.uk
***




--
To unsubscribe:   mailto:[EMAIL PROTECTED]
For additional commands: mailto:[EMAIL PROTECTED]
Troubles with the list: mailto:[EMAIL PROTECTED]




Re: integer value

2002-02-25 Thread Robin Lee

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 = 00; 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 [EMAIL PROTECTED]
To: Tomcat Users List [EMAIL PROTECTED]
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 = 00;
}
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:   mailto:[EMAIL PROTECTED]
For additional commands: mailto:[EMAIL PROTECTED]
Troubles with the list: mailto:[EMAIL PROTECTED]