aspose file tools*
The moose likes JDBC and the fly likes lenght() or row count? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "lenght() or row count?" Watch "lenght() or row count?" New topic
Author

lenght() or row count?

Timy McTipperstan
Ranch Hand

Joined: Feb 17, 2005
Posts: 32
I'm executing a query against my database for a certain type of result. SO not all rows will return, which is expected. How ever I am having an issue in getting the row count or length of the result.

I dont really want to run another query to get the number cant I run .lenght on the result and get the interger?
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
Hi.

The problem is really that there isn't any interaction with the databse until you do something with the result set.

You have 3 options:

(1) As you say, do a 'select count(*)' or 'count( whatever your query is )'
(2) Iterate through your resultset keeping a tally
(3) If you are able to use scrollable resultsets, take a look at this approach.
[ March 15, 2005: Message edited by: Horatio Westock ]
Timy McTipperstan
Ranch Hand

Joined: Feb 17, 2005
Posts: 32
#3 looks like a better option for what I want to do.
thanks
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
Before you decide for sure, take a look at the final section of this article.

You should check that your DB and driver definitely support scrollable cursors, and don't just emulate it. If not, you are basically going to be getting every row anyway.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Since this isn't as easy as it seems like it might be it is worth asking, why do you need to know how many rows have been returned?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Moving to JDBC...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: lenght() or row count?