*
The moose likes Java in General and the fly likes Checking for No Value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Checking for No Value" Watch "Checking for No Value" New topic
Author

Checking for No Value

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
Why won't this work? It never fires any thing but the okay condition. What am I missing that would catch a null/empty resultset?

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Well, perhaps stating the obvious: if you have an empty (no rows) result set, that first "if (rsa.next())" will return false, and you'll get to that one condition that doesn't print anything. Several of those other conditions would throw a NullPointerException if getString() were ever to return null, as you're anticipating.


[Jess in Action][AskingGoodQuestions]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
Wouldn't the if else which I have take care of that?

Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Why doesn't it work for what?

Are you trying to only check the first item in the first column?
That's what you're doing.

There's no loop here.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
Then why do I get an output of:

System.out.println("Here at ok");

If there is no loop?

What would you suggest to fix this?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Originally posted by Steve Dyke:
Then why do I get an output of:

System.out.println("Here at ok");

If there is no loop?

What would you suggest to fix this?


You see that output if that column in the first row of the result set contains valid data. The loop referred to would be need to process any additional rows.

As far as how to fix it: depends what the code is trying to do, exactly. If all you need is one value from one row, then just get rid of all the "null" stuff, and have 'if (rsa.next()) { /* THE OK PART */ } else { /* THE EMPTY-RESULT-SET PART */}'
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
If you look at my code and disreguard the null stuff don't I have exactly what you are suggesting?

The good part is running but the return feild value is null/empty.
[ May 15, 2008: Message edited by: Steve Dyke ]
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
You haven't shown us an entire method, or a return statement. (Or shown us where sarray came from, or stated what it is supposed to contain.)

More information is needed (by us to help you).
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
This is my class. What is happening is invalid value is being generated for the sarray[i][1] either a null or empty something and the dataset creater cannot read:


[ May 15, 2008: Message edited by: Steve Dyke ]
Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265

Steve,

I don't see that you're ever actually checking that the field itself is null, just that a trimmed version of a valid string returned by getString(1) isn't null.


There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1439
    
    1
If you look at my earlier post I had field checking(I thought) but it was suggested I take it out. What do I need to do to check it?
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
Is this where you're getting non-strings?



Do you want to default to zero, or something else to let you know there is an error?

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking for No Value