I am developing an online test website.
I am using Servlet with hibernate. The following codes generates only 1Q randomly selected from the database.
There should be 20 Questions randomly generated from database, without repetition. I tried with for loop , but unsuccessful.
SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum <= 10
fetches all the records whose rownum is less than or equal to 10. but i want only 5 records out of those.
Moreover if it fetches 20 records, a foreach tag will help in the following code?
Yes, i have used native SQL. It works fine. Now I am storing user answers in a collection, and then will compare it with the data(correct answers) stored in database.
I think sql query for randomly generating rows, i.e works slower. So i am using Random class for generating random ids, then storing it into a List. But, how to get the records as per the ids in the list? There are about 90 random ids in the list. Is there any way in which i dont need to run the query 90 times?