Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

rs.next() check for empty recordset gives nullpointer

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Folks,
I'm trying to handle cases where a query results in no results. Instead of an error page, I'd like a friendly message.

Here's what I have:


I found this snippet out on the net, and it looks simple, but I'm getting a nullpointerexception on the line with if (rsStns.next()) {

Am I missing something obvious?

Cheers,
Mike
 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post the stack trace?
 
Mike McMahon
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alas - My sql was botched. I ran it directly (through iSQLPlus) and found an error. I guess Java was right, and i was pointing at null!
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like rsStns is null, which means executeQuery returns null...

I would have hoped that executeQuery either returned some
results (even if empty) or threw an exception though.

The stack trace would be great as rogel suggests.

Have you tried using a simpler sql question?
 
Marshal
Posts: 74661
335
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NullPointerExceptions are usually a beginning topic, but if there is an error in the SQL it might be better to describe the SQL in our databases forum, where I am moving this thread.
reply
    Bookmark Topic Watch Topic
  • New Topic