File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Online test application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Online test application" Watch "Online test application" New topic
Author

Online test application

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
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.


OnlineExam.java



TestServlet.java




TestDao.java



kunal
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Why not randomly select 20 questions from database and set it in the session so that each user can see the random questions at their end.

To get the random rows from database. The link http://viralpatel.net/blogs/2009/05/fetch-random-rows-from-database-mysql-oracle-ms-sql-postgresql-example.html might help.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Hello piyush

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?


Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Oh Sorry. I didn't knew that oracle has rownum internally. Random numbers is generated by the database. I am moving forward to the codings. Thanks
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Now i am stuck with converting that subquery to either HQL or criteria
Piyush Mangal
Ranch Hand

Joined: Jan 22, 2007
Posts: 196
Apart from HQL and Criteria, You can also use native SQL for your query in hibernate.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
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.
Telemart Network
Greenhorn

Joined: Apr 24, 2012
Posts: 4
Nice programme. Online test application is good one to take tests easily & also accurately.


Career Guidance Package English for Beginners
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Thanks
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
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?
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 622
Solved, in Restrctions. class there is a in method which takes 2 args, string property and the collection.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Online test application