This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with empty result set

 
MATT JACKSON
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 rs.next() but if I call rs.getString(1) to check if the string is null I get an SQLException thrown.
HELP!!!
thanks in advance
 
Peter Tran
Bartender
Posts: 783
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt,
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, ResultSet.next() should return false.
For example,

If your code falls inside the while() loop, then the resultset is not empty.
-Peter
[This message has been edited by Peter Tran (edited January 16, 2001).]
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can call rs.next() but it will return false if there are no rows in the resultSet.
 
MATT JACKSON
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot to both replies. I got it working now. That helped alot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic