I need to design a JSP page where i am required to populate the drop down menu from the database. Please let me know how it can be done. Your help would be sincerely appreciated.
Well first you need to get the data from the database using some kind of datasource connection. Then you can write some html to the browser to populate the combo box with a for loop.
// connect to database
Connection conn = ...// get conncetion, don't remember, sorry, you'll have to look that up
Statement stmt = new Statement(conn);
ResultSet rs = conn.executeQuery("SELECT * FROM someTable");
out.print("\ <option>" + rs.getString("column1") + "</option>\
"); // where column1 is the column in the database table
This has to be with an existing html form. I'm assuming you know how to deal with that, if not, just ask and I can give you some info on that.
Well the thing is simple.
<select size="1" name="cName" >
I am pasting this code from my own jsp page.
selectCustomer(); ==> Select data from my DB.
For loop doing your job.
Hope it help.
I want to know how to fill my combo box with values from the database for a field "name".
I have in my action class the following line.
Using dao, I have got values for field "name" and filled it in List list.
How do I write in jsp the select and options tags..
what should be the name field in the select tag ?
Should I use a new getter and setters class?
This topic is now closed. New replies are no longer allowed.