File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes remove null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "remove null" Watch "remove null" New topic
Author

remove null

Li Jenny
Ranch Hand

Joined: Apr 19, 2010
Posts: 57
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

Joined: May 16, 2008
Posts: 7
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

Joined: May 26, 2003
Posts: 31062
    
232

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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
kv ruby
Ranch Hand

Joined: Jul 23, 2009
Posts: 38
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.


Regards, ruby kv
rubyshiv.blogspot.com
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jan 14, 2004
Posts: 19
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: remove null