Re: how to count exactly the rows of a ResulSet



Mariano wrote:
On 27 Giu, 06:03, ben...@xxxxxxxxx wrote:
On Jun 26, 7:11 pm, Martin Gregorie <mar...@xxxxxxxxxxxxxxxxxxx>
wrote:



Mariano wrote:
Then, i have this need, i use this method, it seems works fine, but
for this method there are no differences if the resulSet contain one
row or if resultSet is empty, method return always 1 to me. For
resultSet larger than one row it works perfectly.
This is my semi-functionant code:
public int rowCount(ResultSet r) throws SQLException {
r.last();
int rc = r.getRow();
r.beforeFirst();
return rc;
}
How can I modify it, to have rc=0 if rs is empty, rc=1 if there is one
row in rs, and so on????
Thank u to all...
Regards
last() returns a boolean. Use it.
--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
I was just looking through the docs,

isn't r.getFetchSize() what you're looking for?

--------
public int getFetchSize()
throws SQLException

Retrieves the fetch size for this ResultSet object.

Returns:
the current fetch size for this ResultSet object

--------
Benhttp://www.plink-search.com

using getFetchSize() the result is always 1. Someone help me
pleaseeeeee

I already told you an answer which should work with only minor changes to your current code. If you ignore return values from methods such as last() then of course your code won't work.

Hint: last() returns false if the result set is empty.

A quick look at the ResultSet documentation shows that getFetchSize() (the opposite of setFetchSize() BTW - there's a clue!) shows how many rows are retrieved from the database at a time, not how many rows there are in the result set. getResultSet() is NOT the answer to your problem.



--
martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
.



Relevant Pages

  • RE: Error when closing an empty resultset
    ... "Nance" wrote: ... > I am getting the following error message when I attempt to close an empty ... > resultset from an ADOQuery: ...
    (microsoft.public.data.ado)
  • Re: how to count exactly the rows of a ResulSet
    ... row or if resultSet is empty, method return always 1 to me. ... public int rowCountthrows SQLException { ... martin@ | Martin Gregorie ...
    (comp.lang.java.programmer)
  • Re: how to count exactly the rows of a ResulSet
    ... for this method there are no differences if the resulSet contain one ... row or if resultSet is empty, method return always 1 to me. ... public int rowCountthrows SQLException { ...
    (comp.lang.java.programmer)
  • how to count exactly the rows of a ResulSet
    ... for this method there are no differences if the resulSet contain one ... row or if resultSet is empty, method return always 1 to me. ... public int rowCountthrows SQLException { ...
    (comp.lang.java.programmer)
  • Re: Autocomplete jPopupMenu
    ... then the list is populated and the popup appears, ... If the ResultSet is empty pop up a JOptionPane or use a non-editable JTextField in your query dialogue to tell the user there are no hits. ... Otherwise populate and display your JList to show the results. ... martin@ | Martin Gregorie ...
    (comp.lang.java.programmer)