Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Checking for No Value

 
Steve Dyke
Ranch Hand
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Dyke
Ranch Hand
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wouldn't the if else which I have take care of that?

 
Bill Shirley
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Dyke
Ranch Hand
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 265
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Steve Dyke
Ranch Hand
Posts: 1679
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 457
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic