• Post Reply Bookmark Topic Watch Topic
  • New Topic

drop down list  RSS feed

 
bhavana dixit
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to create a quiz in java in which questions and options will be retrieved from mysql database.I want the options to be in drop down list format.And I am using jsp for presentation layer and all the connections with database are in java...so please can somebody guide me on how to retrieve the options from database to drop down menu...
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bhavana,
Welcome to CodeRanch!

Have you started yet? If not, the first step is to define the table in SQL. And then to write JDBC code to get the data from the database.

Which step are you stuck on? We can give some hints on that step.
 
bhavana dixit
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created the tables and i know how to do connectivity but...how to create list in java to retrieve the data from database and then display it in drop down menu format...
 
bhavana dixit
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Someone suggested me to Retrieve the data into a list of objects (e.g.List<Country>) in a method inside a Java class (DAO)..how to create list in DAO class...??
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bhavana dixit wrote:Someone suggested me to Retrieve the data into a list of objects (e.g.List<Country>) in a method inside a Java class (DAO)..how to create list in DAO class...??


Here's a high-level view. You will have to give it your best shot and post your code and we'll help from there.

Define your SQL statement that you'll be using to retrieve the data. You'll be using it as a PreparedStatement.
Create the List<Country> object.
Make the connection.
Run the query which will return a ResultSet.
Loop through the ResultSet using a "while (resultSet.next())".
Inside that while loop, you'll create a Country object and populate it using the various getXXX methods of ResultSet.
At the end of the loop, add the Country object to the List<Country> that you defined earlier.
This process will continue until there are no more records in the ResultSet.
Once your while loop has ended, return the List to the caller, either a servlet or helper object.

Dive in and give it a try and post your results. Good luck.

And welcome to the Ranch!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!