Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Selecting random records

 
Sri Rangan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After I retrieve the records from database by some search criteria, I need to randomly pickup particular number of records based on the user input.
Assuming database resultset retrieves 1000 records and I have pick up 350 random from them
Is there a good way to approach this.
Sri
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the ResultSet.absolute(int rowNumber) method; I think that would solve your problem.
kind regards
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would want to generate the 350 random numbers into an array, sort them, and then either use the absolute() method or simply iterate through the ResultSet only keeping the records that match an entry in your array. Bouncing around back and forth through the ResultSet would probably be a performance pig.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic