aspose file tools
The moose likes JDBC and Relational Databases 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 The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 3740
    
  10

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


[OCA 8 Book] [Blog]
Scott Selikoff
author
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3740
    
  10

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: 3740
    
  10

There is no method in java to randomize result sets but it would be trivial to do so in an application.
 
Have you tried LearnNowOnline? http://www.learnnowonline.com/
 
subject: retrieve values randomly ?