wood burning stoves 2.0*
The moose likes Servlets and the fly likes ResultSet and count urgent please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "ResultSet and count urgent please help" Watch "ResultSet and count urgent please help" New topic
Author

ResultSet and count urgent please help

santosh vashist
Greenhorn

Joined: May 14, 2001
Posts: 25
Hi All,
I am using a ResultSet to retriev data from database. After the action i want to know whether any record is present or not.
What i have done is I have used
if(Rs.next())
{
out.println("present")
}
The problem is My result set returns only one record and if i say rs.next() to check the presence of any record the pointer will move to first record.
Next if i have to take the record to some variable i use
while (rs.next())
{
temp=rs.getString("name");
}
here i am getting an exception as because the pointer has already moved and there is no record.
So how to check for presence of any record in a resultset without using .next() method.
it would be greate if any body tells the solution for this.
thanks in advance
santosh
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Only call next() test in the condition of the while loop. It will give you the results your after. If there aren't any results returned, the very first call to while(rs.next()) will return false and the code inside will not be executed.
------------------
Hope This Helps
Carl Trusiak, SCJP2


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResultSet and count urgent please help
 
Similar Threads
Urrgent Pls Advice as soon as possible
while (rs.next()) not stopping at EOF.
JDBC Drivers
how can I get the record number of resultset?
isLast method for result set is not working