title: Multiselect Dropdown selected
body: <p>I have multiSelect drop down on my web page designed in JSP. End user will select required options and save the form to Database.   Below is the original Dropdown that gets values and index from Database Master Table. Selected values are saved in another table.</p>
  
  <p>Original Dropdown on the page. </p>
  
  <pre><code> &lt;table&gt;
   &lt;tr&gt;
   &lt;td&gt; Departments Impacted   &lt;/td&gt;
      &lt;td&gt;&lt;select multiple="multiple" name="abc" id="abc"&gt;
       &lt;%
  
           Statement stt3 = conn.createStatement();
           ResultSet rstt3 = stt3.executeQuery("SELECT DEPT_DEPARTMENT_ID, DEPT_NAME FROM [PA].[dbo].[PA_DEPT_DEPARTMENT] ORDER BY DEPT_NAME ASC");
           while (rstt3.next()) {
  
           %&gt;
  
           &lt;option value="&lt;%=rstt3.getString(1)%&gt;"&gt;&lt;%=rstt3.getString(2)%&gt;
           &lt;/option&gt;
           &lt;%
               }
              stt3.close();
       rstt3.close();
                              %&gt;
      &lt;/select&gt;&lt;/td&gt;  &lt;/tr&gt;
  </code></pre>
  
  <p></p>
  
  <p>Below code retrieve saved database values and display them as selected in new <strong>select</strong> tag. However, I want the selected values to be show in above table instead of new Dropdown.  </p>
  
  <pre><code>&lt;%
   ArrayList al = new ArrayList();    
   String dept = null;
   String deptID = "SELECT DEPARTMENT_ID FROM  [PA_RD_DEP_REQ_DETAILS_DEPARTMENT_MAP] inner join  [PA_RD_REQUISITION_DETAILS] on RD_DEP_RD_ID=RD_ID where RD_ID=?";
  
           PreparedStatement pst4 = conn.prepareStatement(deptID);
           pst4.setString(1, RD_ID);
           ResultSet rstt1 = pst4.executeQuery();
           while (rstt1.next()) {
               dept=rstt1.getString(1);
              al.add(dept);
  
           }
           for(int i=0; i&lt;al.size(); i++)
           {
           String deptName = "SELECT [DEPT_NAME] FROM  [PA_DEPT_DEPARTMENT] WHERE [DEPT_DEPARTMENT_ID]=?";
           PreparedStatement pst5 = conn.prepareStatement(deptName);
           pst5.setString(1, (String)al.get(i));
           ResultSet rstt5 = pst5.executeQuery();
           while (rstt5.next()) {
               %&gt;
               &lt;option value="&lt;%=(String)al.get(i)%&gt;" selected="selected"&gt;&lt;%=rstt5.getString(1)%&gt;
               &lt;%  
  
  
           }
           }
  
  
           %&gt;
  </code></pre>