File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes ResultSet Manipulation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "ResultSet Manipulation" Watch "ResultSet Manipulation" New topic

ResultSet Manipulation

David Menfields

Joined: Jun 28, 2005
Posts: 7
Hi Everyone,

I need to know, is there any possibility for us to get a limited count of records from resultset ?

Basically, the problem is , if the query result - resultset returns more than 10000 records, i couldn't able to get all the records in the Swing client..returning Out of Memory error.So, we decided to show some 5000 records to the client.Ofcourse, i can use setMaxSize() to get limited the query result.But , we have to show the total record count in another text field ..

So, my idea is , fetch all the records using resultset..
get the total count...then filter only 5000 records to display to the only i need the there any way to filter only limited count of records from resultset ?

Primary objective is, to finish this operation in a single database call...

I appreciate your suggesstions and ideas on this .

Thank You !
Scheepers de Bruin
Ranch Hand

Joined: Jul 19, 2005
Posts: 99
int a =0;
while (a<1000 &&{
//do stuff with records

We're doomed!!<br />Yay!!!<br />No that's bad Girr!!<br />Yay!!!
Makarand Parab
Ranch Hand

Joined: Dec 10, 2004
Posts: 121
I would design to fire two queries. First one give me total count and the next one 5000 records.
Another best solution would be to write a stored procedure which returns 2 resultset. First resultset holds the total count and next one 5000 records. This keeps the logic at one place and easy to debug, morever you can write clean code at front end.

Makarand Parab
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 751
Hi, if I remember right... There is an SQL statement that allows you to get a limited amount of record... Something like... SELECT * FROM tbl_name LIMIT 10... Something like that... I suggest you google it...

SCJP 1.5
Scheepers de Bruin
Ranch Hand

Joined: Jul 19, 2005
Posts: 99
MS SQL Server: SELECT TOP 10 * FROM bla bla
[ October 18, 2005: Message edited by: Scheepers de Bruin ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63852

The syntax to limit the number of rows returned is DB-dependent. You'll need to look up which syntax is appropriate for the DV that you are using.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: ResultSet Manipulation
It's not a secret anymore!