• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Null or blank String into database

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

i have a jsp form, user is going to fill the form.

if user doesn't fill any filed in the form then what should i insert into database for that filed. is it a blank string or null?

waiting for the answer.

thanks in advance
 
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bhargav,

That is depending on you.... No matter what you insert into database..it does not make sense.... blank string or null...

 
bhargav shankar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks nishan,

but is there any use if i insert null into database ?

Which is the better option?
 
Nishan Patel
Ranch Hand
Posts: 689
Scala Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just make your flied into database not null= false and that will automatically set null value when user not input any thing..
I recommend insert null instead of blank string.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What are the requirements of your application. First of all, it looks liek the field is nto required. If that's not the case, then validate on the client to make sure something is entered before allowing form submission. If the field is not a required field, then is the column defined as not null in the database table?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Blank strings and null values are different for a reason, they have different logical meanings. Suppose you have a table with a field called "my_string_value" and allow your domain model to represent no value as a zero length string. How do you now query the database for all records where "my_string_value" is not set? You have to use database functions to do this, which can be inefficient and often database specific. If its null you can easily test.

Another thing to consider: in Oracle, you cannot store a zero length string. So if you have the same field you must default it to a single space (or some other suitable default).

 
reply
    Bookmark Topic Watch Topic
  • New Topic