• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Fetch only 'n' records from the ResultSet

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted my Resultset to get only the last 'n' records from the resultSet.

Say for Example, My Query Return 10 rows and i wanted to display only the last 4 records of the query.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Ameya Thakur:
I wanted my Resultset to get only the last 'n' records from the resultSet.

Say for Example, My Query Return 10 rows and i wanted to display only the last 4 records of the query.



Hi Ameya,

This can be done in java as well as on DB side. Which way you want to do it depends on your total number of records and some other factors.

1. In java approach, fetch all records from DB. Then using ScrollableResultSet, display only certain number of records each time.

2. In DB approach, write a query such that you will only fetch those records which are to be displyed. Here, for showing next set of records, you have to query the DB again. I have not used this approach much, but these queries are usually written using default "ROWNUM" field (I am talking about Oracle).

I Hope this will help.

Sachin
 
Ameya Thakur
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Sachin,

Thanks for your help, But this solution wont solve my problem.

As i am using Scrollable ResultSet the ResultSet is Fetching me 10 rows
and i have a field in the Table called as Concurrency which tells me how many time the record has been updated.

So Depending upon the Concurrency Count i want to get those Many Records

for which i am doing is

if (lConCurrencyCount >=1 && lResultSet!=null)
{
lResultSet.last();
while(ltempCurrencyCount!=0)
{
lResultSet.getString("AA");
}
}

Now the Data which i am getting is in the reverse order(10th record first the 9th & so on which i need to chnage).
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To pull the data in the order you need can you not do an "ORDER BY" in the SQL statement?
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I feel this is a simple logical issue.

You can always subtract the concurrency count from 10 , get the remaining ( say 'n') and then do a
rs.absolute(n) and start moving ahead !

-G
 
Ameya Thakur
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Gagan,

Thanks for your help , i had use the same rs.absoulte() and i am passing the parameter as -5 so that we can read from the 5th Record..

Regards

Ameya
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!