This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Help with empty result set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Help with empty result set" Watch "Help with empty result set" New topic

Help with empty result set


Joined: Nov 29, 2000
Posts: 5
I have a servlet that accesses a MySQL DB. What it does is scan the input from a JSP to see if the entry being added already exixts. It does this by querying the DB for an ID number. The query is: SELECT idNum FROM students WHERE idNum = inputNum;
The problem i have is that if the query returns nothing, I can call but if I call rs.getString(1) to check if the string is null I get an SQLException thrown.
thanks in advance
Peter Tran

Joined: Jan 02, 2001
Posts: 783
If your driver implementation is correct, then you shouldn't run into this problem. When you execute the query, and there are no rows in the database matching your where clause, then your ResultSet should be empty. In this case, should return false.
For example,

If your code falls inside the while() loop, then the resultset is not empty.
[This message has been edited by Peter Tran (edited January 16, 2001).]
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You can call but it will return false if there are no rows in the resultSet.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog

Joined: Nov 29, 2000
Posts: 5
Thanks alot to both replies. I got it working now. That helped alot.
I agree. Here's the link:
subject: Help with empty result set
It's not a secret anymore!