Reputation: 3062
<select name="supplier">
<%
try {
Connection conn = JavaConnect.ConnectDb();
Statement stmt = conn.createStatement();
ResultSet rs;
rs = stmt.executeQuery("SELECT name FROM supplier ");
while(rs.next()) {
out.write("<option value ="+rs.getString("name")+"</option>");
}
rs.close();
stmt.close();
}
catch(Exception e) {
System.err.print("Sorry");
}
%>
</select>
I am trying to populate a combo box in a jsp page and have tried the above but im getting an empty combo box. I've researched other answers but most of them don't seem to work.
Upvotes: 0
Views: 2772
Reputation: 23415
First you shouldn't be using java code in your JSP page. EL is for that purpose. All this code should go into the server side. Check SO Servlets Wiki page of the proper use.
But lets say your result set is returning something. So try this then:
out.write("<option value=" + rs.getString("name") + ">" + rs.getString("name") + "</option>");
If you'll see empty list again, then your result set is empty.
Upvotes: 2