Solved

Random Questions from MS Access to a label

Posted on 2004-08-22
9
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Configure a Bean in an XML file 4 49
servlet web applications   metadata-complete="true" or false 3 191
Bot application - advice 3 60
glassfish admin console 1 21
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 video teaches viewers about errors in exception handling.

749 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