Populating drop down menu's from database dynamically
Hi
I m facing a problem of populating the drop down menu from a MS Access database using JSP. But i m not able to do it. Can you please help me out?
this works perfectly for textarea
<textarea cols="20" rows="20">
<% for(int i =1; i <=rsmd.getColumnCount();++i)
out.println(rsmd.getColumnName(i)); %>
</textarea>
but for drop down box it gives problems
Heres the code!
<select name="aa" ID = "aa">
<option value="<% for(int i =1; i <= rsmd.getColumnCount();++i)
out.println(rsmd.getColumnName(i)); %>" > </option>
</select>
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 61 in the jsp file: /gv/event.jsp
Generated servlet error:
i cannot be resolved
wat can be the alternative? Please hlp
Regards
Sami
[925 byte] By [
sami_azmia] at [2007-11-26 17:46:29]

# 2
sorry but it gives this error now!
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 64 in the jsp file: /gv/event.jsp
Generated servlet error:
Syntax error on token ";", delete this token
and after deleting, which is syntactically incorrect it doesnt work!
Message was edited by:
sami_azmi
# 5
Thanks for the reply,
Every thing is now error free But the problem still remains.
the values are not shown in the dropdown menu, no value is added in it. i tried adding value of i that too was not shown, i donno wat the problem can be.
these Codes were used and they are working without error.
<select>
<option value= "-">-
<% for(int i =1; i <= rsmd.getColumnCount();++i) { %>
<option value="<% out.write(rsmd.getColumnName(i)); %>" > </option>
<% } %>
</select>
<option value="<%=rsmd.getColumnName(i))%>"
can u pls suggest the remedy!
Sami>
# 6
<option value="<% out.write(rsmd.getColumnName(i)); %>" > </option>
should be
<option value="<% out.write(rsmd.getColumnName(i)); %>" >
<% out.write(rsmd.getColumnName(i)); %></option>
the value= is what is returned to you when they select it, the second one before the </option> is what they see. That way they don't have to be the same ie
the value could be "bc" and the option they see is "Britsh Columbia"
Lena