-
JDBC resultset
how can i find the no of rows returned in a resultset object.
i want to limit the no of rows returned thru select stmt.
database is oracle.i m using JSP.
-
Re: JDBC resultset
One way to find the number of rows returned is to read them all. Obviously
this is not what you want to do. Another way to do this is to first create
a summary resultset, using SQL that looks like "Select count(*) from <same
table, same where clause, same group by clause>". This will return a single
row with a single column that tells you how many rows will be in the detail
resultset.
There is no method like "rowCount()" because the JDBC driver may not know
how many rows will be returned in the resultset when it gives it to you.
For example, it may use a database index that matches your selection; in
this case, it may just return the next record from the index when you do
resultset.read().
prashant jani <janiprashant@yahoo.com> wrote in message
news:3993f3ff$1@news.devx.com...
>
> how can i find the no of rows returned in a resultset object.
> i want to limit the no of rows returned thru select stmt.
> database is oracle.i m using JSP.
-
Re: JDBC resultset
>> how can i find the no of rows returned in a resultset object.
>> i want to limit the no of rows returned thru select stmt.
>> database is oracle.i m using JSP.
Here's another way, labourious but it gets a solid result:
// assumes rs == a current resultset
public int count()
{
if (rs == null) return 0;
int currentRow = rs.getRow(); // save the row pos
rs.last();
int num = rs.getRow();
if (currentRow == 0)
rs.beforeFirst();
else
rs.absolute(currentRow);
// go back to original row
return num;
}
-
Re: JDBC resultset
For this to work, you will depend upon JDBC 2.0. if it it supported by the
database you are using, then it's ok, otherwise you can't use this style
to get the rowcount and your only alternative is to issue a count(*) command.
"Marty" <marty@dot.net.au> wrote:
>
>>> how can i find the no of rows returned in a resultset object.
>>> i want to limit the no of rows returned thru select stmt.
>>> database is oracle.i m using JSP.
>
>Here's another way, labourious but it gets a solid result:
>
>// assumes rs == a current resultset
>
>public int count()
>{
> if (rs == null) return 0;
>
> int currentRow = rs.getRow(); // save the row pos
> rs.last();
> int num = rs.getRow();
> if (currentRow == 0)
> rs.beforeFirst();
> else
> rs.absolute(currentRow);
> // go back to original row
>
> return num;
>}
>
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks