aspose file tools*
The moose likes Servlets and the fly likes Null and Blank in Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Null and Blank in Database" Watch "Null and Blank in Database" New topic
Author

Null and Blank in Database

Rashmi Trivedi
Ranch Hand

Joined: Aug 13, 2001
Posts: 60
Dear Friends
I have one confusion about Null and Blank. According to my experience, null fields in Database are not welcomed. Is that correct? I experienced that if reference that null fields in you sql query from servlet, sql query get confused and may not return any thing.
Some of my friends told me that fields can be blank in Database. Blank is 0 length string. Is that true?
Rashmi
Sreenivasa Majji
Ranch Hand

Joined: Jul 12, 2001
Posts: 224
Null and blank are two different things. I have no idea what kinds of problems you are facing regarding nulls in servlets. Some sample code may help on this.
Null is not 0 length string.
String str1 = "";
String str2 = null;
Here str1 is a string with zero length, where as str2 is null.
Originally posted by Rashmi Trivedi:
Dear Friends
I have one confusion about Null and Blank. According to my experience, null fields in Database are not welcomed. Is that correct? I experienced that if reference that null fields in you sql query from servlet, sql query get confused and may not return any thing.
Some of my friends told me that fields can be blank in Database. Blank is 0 length string. Is that true?
Rashmi


------------------
Sreenivasa Kumar Majji
Sun Certified Java Programmer
SCJP Mock Test


Sreenivasa Majji
Rashmi Trivedi
Ranch Hand

Joined: Aug 13, 2001
Posts: 60
Dear Sreenivasa
Thank you for your reply. The problem i am having is this:
I have some fields on HTML page which are optional. If there is no input from user than i don't bother logging that information into database and if user does than i do log that into database.
I have if statement inside my servlet to check user input:
if(fName !=null) {
//execute insert query
}// end if
This statement doesn't work the way it suppose to. It doesn't matter if user have any input or not it execute insert query.
I also tried following code but same result:
if(fName !="") {
//execute insert query
}// end if
Hope this make sense...
Regards
Rashmi
Adam Hardy
Ranch Hand

Joined: Oct 09, 2001
Posts: 566
hi rashmi,
you've got two seperate things here - nulls/blanks coming from the http request and nulls/blanks coming from the database. it's still difficult to tell what exactly you're problem is.
note well though: null means "no value", but "" (zero length string) is a value.
a date can also be null - have no value - but it can't be zero length (can it?)

I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Vijay Kashyap
Ranch Hand

Joined: Jul 30, 2001
Posts: 74
Hi Rashmi,
The problem you have defined is still not clear but I think you are looking to avoid executing a query if the data passed / received is null or blank.
You can check something like

Cheers,
Vijay
Malhar Barai
Author
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
dear rashmi
u can try this too
if(fname.equals(""))
{
//execute query
}
good luck
malhar
Originally posted by Rashmi Trivedi:

if(fName !=null) {
//execute insert query
}// end if
This statement doesn't work the way it suppose to. It doesn't matter if user have any input or not it execute insert query.
I also tried following code but same result:
if(fName !="") {
//execute insert query
}// end if
Hope this make sense...
Regards
Rashmi



Malhar Barai
SOA & Java Book
Rashmi Trivedi
Ranch Hand

Joined: Aug 13, 2001
Posts: 60
Hello Friends
Thank you for input. I really appreciate it. I will try all the suggestion that i got from you and get back to you if it works. I have another problem which i need to fix first.
Once again thank you.
Regards,
Rashmi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null and Blank in Database