• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 191
  • Last Modified:

Random Questions from MS Access to a label

I want to ask about JDBC Java.
I have created an application "Examination System" but the final problem I encountered is that I have placed a "Label" in a Window and  I need this label to get the random questions from Database of MS Access but the question already appeared should not be comeup again next time for another label.
 
Required features are :
1 Database file containing questions
1 GUI Window with 1 Label
and a connection between my database questions and label.
0
vicky2k
Asked:
vicky2k
  • 3
  • 3
1 Solution
 
CEHJCommented:
Set the label text with setText().

Keep a Set of question ids. Make sure the new question not already in the Set
0
 
girionisCommented:
How many question do you have? You can load all of them up, put them in a collection and then shuffle. Then use the collection to display the question to a label.
0
 
girionisCommented:
Lets say you have a ResultSet "rs" with all the questions:

ArrayList list = new ArrayList();
while (rs.next())
{
    list.add(rs.getString(1));
}

Collections.shuffle(list);

label.setText(list.get(index));

You could have an instance variable "index" that increments everytime a question is requested from the collection.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
girionisCommented:
You will also need to cast the list element to String.
0
 
CEHJCommented:
girionis' suggestion is similar, but if you place the questions in a Set, they'll already be 'shuffled' as a Set is unordered.
0
 
CEHJCommented:
Forget that last suggestion of mine - it'll make it difficult to remove a question from the Set. Stick with girionis
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now