Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Checking for No Value

 
Ranch Hand
Posts: 2140
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2140
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wouldn't the if else which I have take care of that?

 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2140
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2140
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2140
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 265
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2140
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?

 
Anderson gave himself the promotion. So I gave myself this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic