0
<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.

Filburt
  • 17,626
  • 12
  • 64
  • 115
Hoody
  • 2,942
  • 5
  • 28
  • 32
  • You should be [avoiding](http://stackoverflow.com/a/3180202/1037210) using Scriptlet from now on. – Lion Jan 11 '13 at 15:23

1 Answers1

2

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.

Community
  • 1
  • 1
Paulius Matulionis
  • 23,085
  • 22
  • 103
  • 143