| Author |
rs.next() check for empty recordset gives nullpointer
|
Mike McMahon
Ranch Hand
Joined: May 07, 2005
Posts: 30
|
|
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
Joined: Dec 19, 2003
Posts: 41
|
|
|
Can you post the stack trace?
|
SCJP 1.4
|
 |
Mike McMahon
Ranch Hand
Joined: May 07, 2005
Posts: 30
|
|
|
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
Joined: Mar 18, 2003
Posts: 118
|
|
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
Joined: Oct 13, 2005
Posts: 32687
|
|
|
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.
|
 |
 |
|
|
subject: rs.next() check for empty recordset gives nullpointer
|
|
|