File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

rs.next() check for empty recordset gives nullpointer

 
Mike McMahon
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
rogel garcia
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the stack trace?
 
Mike McMahon
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
Jonas Isberg
Ranch Hand
Posts: 118
  • 0
  • Mark post as helpful
  • send pies
  • 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?
 
Campbell Ritchie
Sheriff
Pie
Posts: 47258
52
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic