| Author |
how to check for null string in resultset
|
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26499
|
|
Someone e-mailed me this question. Normally I just say to use the forums. But I really want to answer this one. So posting the question here.
I was hoping you could help me with a question I had in Java. So I'm
using a Result Set to get a result. However, one of my strings has a
null value. I've tried:
If(rs.getString("gender")==0)
If(rs.getString("gender")==null)
If(rs.getString("gender").equals(""))
If(rs.getString("gender").matches(""))
but none of them work. Can you please tell me how to check if the
'gender' field is null or not?
|
[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
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26499
|
|
|
Call rs.wasNull() right after calling rs.getString(). It returns a boolean telling you if the last value returned was a database null.
|
 |
Scott Selikoff
Saloon Keeper
Joined: Oct 23, 2005
Posts: 3673
|
|
|
If it's a string, ==null should work. Is it possible you're storing an empty string instead of null in your database? Try running a query with 'WHERE gender IS NULL' in the database and see if it returns any records.
|
My Blog: Down Home Country Coding with Scott Selikoff
|
 |
 |
|
|
subject: how to check for null string in resultset
|
|
|