Forums Register Login

How to check if resultset has only one row or more?

+Pie Number of slices to send: Send
I have to do a query to a table. If resultset has only one row, I have to set the bean in one particular way and if the resultset has multiple rows in a different way.
I tried


The problem with this code is even if the row count from the query is one, it sets ABC into the bean.
Should I try to get the count and then check if count > 1? If that is the case, then I have to do two queries, one to get the count and the other to do the query itself. Please advise.
Thanks in advance
Vidyaram

+Pie Number of slices to send: Send
Just read the records to find out how many there are:


But if it were me I would be considering writing a query involving "count(*)" rather than potentially returning a large number of rows just to ignore them.
+Pie Number of slices to send: Send
 

Paul Clapham wrote:But if it were me I would be considering writing a query involving "count(*)" rather than potentially returning a large number of rows just to ignore them.


Indeed; this is the best way
+Pie Number of slices to send: Send
Thank you for posting the answers quickly!

Vidyaram
I've never won anything before. Not even a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 5218 times.
Similar Threads
ResultSet
EJBQL and its return type
Displaying few rows on each page
Record Count
How to find the size of my resultSet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 10:24:02.