Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking string

 
sreeni san
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I retrieve data(String values of X column) from Database.
Data in database will be any of the three
a. "NULL"
b. some value
c. nothing(blank)
note: blank refers to empty not blank space

I need to set values based on the data(String) received like
If the value is not null
if(data!=null or when data is empty)
x="y";
I am facing problems when data is empty. How will my if condition be?
It cannot be if (data.length==0) or if(data.equals("")) as when data will be "null", null pointer exception will be thrown
Kindly suggest a suitable soluton.
Thanks
sreeni
 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a wasNull()method in the ResultSet interface. it indicates if the recently retrieved column is null

Bosun
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic