• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

remove null

 
Li Jenny
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can i remove the null field in mysql because db store the null value.
when i retrieve it , then display 'null'
 
Satya Sakhinetipalli
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Li Jenny wrote:how can i remove the null field in mysql because db store the null value.
when i retrieve it , then display 'null'

Can you provide more information about how are you reading the data from mysql? are you trying to display on jsp page?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jenny,
Null is a valid value. What do you want to happen? You can check for a null String or call isNull to make something different happen.
 
kv ruby
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi jenny,

You can use the following whil retrieving data.

SELECT name FROM Table WHERE address IS NOT NULL

or in java code

if( rs.next()!=null) //rs is object of ResultSet

and avoid the null appearing.

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kv ruby wrote:
or in java code

if( rs.next()!=null) //rs is object of ResultSet

That's incorrect in at least a couple of ways: rs.next() returns a boolean, and if having a null address is a normal condition, you wouldn't want to query on it or check if you didn't get any results--the issue (seems to be, anyway) that when the address value *is* null the original poster doesn't want "null" to show up for the user.
 
ss kumar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couple of different ways.

Option 1: Add a constraint to the column to not allow null and insert an empty string. There may be other reasons for allowing null, but if not needed then don't allow.
Option 2: Handle in UI. Use conditional statement Eg: (value==null) ? "" : value;

kumar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic