Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 214
  • Last Modified:

Adding value to combobox

Hi,

I have a combo box:

Color
<select name="col">
<option value='red'>Red</option>
<option value='blue'>Blue</option>
<option value='white'>White</option>
<option value='green'>Green</option>
<option value='black'>Black</option>
</select>


Values are set at the combo box using the option

How do i get it to get value from database,

for example i have a table
called Color with colorid and description.
How do i do it so that i could add new colors and it gets added to combo.And if i delete the value from database, it gets deleted from combo as well

Thanks
0
Jasbir21
Asked:
Jasbir21
  • 2
1 Solution
 
kennethxuCommented:
I asume you familiar with JDBC programming and know how to get a resultset from database, and there is what you need to do in your jsp page:
<%
   // jdbc code to get ResultSet from database:
   ResultSet rs = stmt.executeQuery( "select colorid, colordesc from color" );
%>
<select name="col">
<% while( rs.next() ) { %>
<option value='<%=rs.getString(1)%>'><%=rs.getString(2)%></option>
<% } %>
</select>
0
 
kennethxuCommented:
in case you need information on jdbc programming:
http://java.sun.com/docs/books/tutorial/jdbc/basics/
http://www.javaolympus.com/freebooks/FreeJDBCBooks.jsp

let us know if you have further enquires.
0
 
Jasbir21Author Commented:
Thank you very much.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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