Re: number of rows in a resultset
From: Peter Kirk (peter)
Date: 06/09/04
- Next message: Andy Fish: "Re: Difference between these two class declaration"
- Previous message: Thomas Weidenfeller: "Re: Which IDE to choose (more specific than earlier, very similar post)?"
- In reply to: Michael Rauscher: "Re: number of rows in a resultset"
- Next in thread: Elrod: "Re: number of rows in a resultset"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 9 Jun 2004 13:42:12 +0200
"Michael Rauscher" <michlmann@gmx.de> skrev i en meddelelse
news:ca6im8$bn0$01$1@news.t-online.com...
> Liz schrieb:
> > I'm just starting to use JDBC and want
> > to know the number of rows in a result set
> > but have not been able to figure it out.
> >
> JDBC allows the driver to read the results in chunks. That means, that
> the driver needs not to read the complete result set at once. This is
> important due to perfomance and economical memory management. On the
> other hand that means, that there's no way to know the number of all
> records in advance.
>
> If your ResultSet isn't scrollable, then you have to walk through it:
>
> int i = 0;
> while ( rs.next() )
> i++;
>
> But if your ResultSet isn't scrollable, you can't return back, so you
> would have to execute the query twice if you want to know the number of
> records before processing the results.
A possible problem of course being that the data could change between
queries, and the number of rows returned be different.
Also, maybe the first query could be an SQL "count", and the second query
the actual data retrieval. This still has the possible problem of changing
data, and as I am no SQL expert I have no idea if it would provide any
advantage.
Or, you could iterate throug the result set, and create "business objects"
for each row - after this you have your count, and the data to work with.
Depends on your application of course.
Peter
- Next message: Andy Fish: "Re: Difference between these two class declaration"
- Previous message: Thomas Weidenfeller: "Re: Which IDE to choose (more specific than earlier, very similar post)?"
- In reply to: Michael Rauscher: "Re: number of rows in a resultset"
- Next in thread: Elrod: "Re: number of rows in a resultset"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|