I have never come across a way to return a random order result set. One way to do this might be to do a SELECT returning only the primary key value for each row:
SELECT mytable_id FROM mytable ...
Then, put the results into a java.util.List. Then randomize the list (not too hard to do). Then, run a new query, iterating through the random order list of primary key values - something like this (assume your primary key is simple, one column, integer):
You could also just read the results into a java.util.List containing arrays representing each record, then randomize that.
It all depends on how fast it needs to be and how large your result sets might be.
Jeff Ash<br /><a href="http://www.excellentiasoftware.com" target="_blank" rel="nofollow">Excellentia Software</a>
The short answer is there's not way to do it in JDBC, its more of a java issue.
As previously mentioned, reading all the results into a data structure and randomizing will work with the catch you may retrieve a lot more results than you need (for large tables). In those cases, such as only need one random record out of thousands, it might be better to use a WHERE clause and pick random IDs. The problem with that though, is your IDs have to be numeric and consecutive (ergo no missing IDs between a range of numbers). In the case they aren't, you'd want to add a column to accomplish this.