File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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
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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    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
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3697
    
    5

There is no method in java to randomize result sets but it would be trivial to do so in an application.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: retrieve values randomly ?
 
Similar Threads
how to search values in database
Sent collection through URL
Dynamic values in Multi Select Box when value in Combo box changes
Selecting random records
How to store a check box in DataBase??