• Post Reply Bookmark Topic Watch Topic
  • New Topic

retrieve values randomly ?

 
Saurabh Naik
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can I retrieve values from database randomly ?
suppose in my database there are 13 rows . and I want to retrieve these in random order ?
is there any method to do it ?
 
Sandeep Kumar S Jakkaraju
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can do "order by rand()" .....if it is an rdbms ......
 
Scott Selikoff
author
Bartender
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really. The best solution would be to randomize the returned data in the object/list/array you are storing them in.
 
Scott Selikoff
author
Bartender
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many records are we talking about? Unless your passing the result set to the presentation layer (scary) I don't see how your not putting things into memory. A resultset is just a database-backed hashmap.
 
Saurabh Naik
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Jean.. it works with order by rand()..
but is there any mechanism to fetch result randomly through function..
what is this ResultSet.FETCH_UNKNOWN... how to use it ?
 
Scott Selikoff
author
Bartender
Posts: 4033
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no method in java to randomize result sets but it would be trivial to do so in an application.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!