aspose file tools*
The moose likes JDBC and the fly likes retrieve values randomly ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "retrieve values randomly ?" Watch "retrieve values randomly ?" New topic
Author

retrieve values randomly ?

Saurabh Naik
Ranch Hand

Joined: Apr 24, 2008
Posts: 87
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 ?


SCJP 6 (88%), SCWCD 5 (78%), preparing for SCBCD
Sandeep Kumar S Jakkaraju
Ranch Hand

Joined: Oct 18, 2006
Posts: 37
you can do "order by rand()" .....if it is an rdbms ......


I write like Jean Paul Sarte but in Java....
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

Not really. The best solution would be to randomize the returned data in the object/list/array you are storing them in.


My Blog: Down Home Country Coding with Scott Selikoff
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

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

Joined: Apr 24, 2008
Posts: 87
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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3710
    
    5

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.
 
subject: retrieve values randomly ?