Solved

Random Questions from MS Access to a label

Posted on 2004-08-22
9
165 Views
Last Modified: 2010-03-31
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
Comment
Question by:vicky2k
  • 3
  • 3
9 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11867648
Set the label text with setText().

Keep a Set of question ids. Make sure the new question not already in the Set
0
 
LVL 35

Expert Comment

by:girionis
ID: 11867659
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
 
LVL 35

Accepted Solution

by:
girionis earned 250 total points
ID: 11867669
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 35

Expert Comment

by:girionis
ID: 11867671
You will also need to cast the list element to String.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11867676
girionis' suggestion is similar, but if you place the questions in a Set, they'll already be 'shuffled' as a Set is unordered.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11867689
Forget that last suggestion of mine - it'll make it difficult to remove a question from the Set. Stick with girionis
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count8 challlenge 13 87
IT Company 5 69
return in catch statement 1 40
where is session ID cache stored 1 40
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now