title: How to dynamically populate the drop down list in my JSP page from the database?
body: <p>I am working with <code>JSP</code> and <code>Ajax</code> for the first time. I am trying to get one column data from database and populate it in my drop down list in my JSP page using Ajax call. I don't want to refresh the page so that is the reason, I am making aN Ajax call.</p>
  
  <p>Here is my <a href="http://jsfiddle.net/4Nmqk/104/" rel="nofollow">jsfiddle</a> which has Process button and as soon as I click Process button, it will show an empty drop down list as of now. This is in my another <code>test.jsp</code> page.</p>
  
  <p>I have a table as <code>account</code> and I need to make this select query from the jsp -</p>
  
  <pre><code>SELECT USERS FROM ACCOUNT;
  </code></pre>
  
  <p>As soon as I am clicking Process button, I need to execute above SQL query on my POSTGRESQL database using Ajax. And whatever users, I am getting back from the database, I need to populate those <code>USERS</code> in my drop down list as shown in my above jsfiddle. </p>
  
  <p>Below is my JSP page (databasecall.jsp) in which I am making a call to my database to get all the <code>USERS</code> -</p>
  
  <pre><code>&lt;%@page contentType="text/html; charset=UTF-8" %&gt;
  &lt;%@ page import="java.sql.*" %&gt;
  &lt;%
      response.setContentType("application/json");
  
      try {
          // Step 1. Load the JDBC driver
          Class.forName("org.postgresql.Driver");
  
          // Step 2. Create a Connection object
          Connection con = DriverManager.getConnection(
                  "jdbc:postgresql://localhost/test","root", "root!");
  
          Statement s = con.createStatement();
  
          String sql ="SELECT USERS FROM ACCOUNT";
          ResultSet rs = s.executeQuery(sql);
  
          while (rs.next()) {
              // what to do here?
          }
          rs.close();
          s.close();
          con.close();
      } catch (Exception e3) {
          e3.printStackTrace();
      }
  %&gt;
  </code></pre>
  
  <p><strong>Problem Statement:-</strong></p>
  
  <p>Now my question is, how do I populate all the <code>USERS</code> data which I got from the database in my drop down list in the <code>test.jsp</code> page? Meaning, somehow I need to call this JSP on the Process button click and then pass all the users data which we got and then dynamically populate the drop down list?</p>
  
  <p>Suppose if I am getting 10 USERS from the database, then the drop down list should have 10 users in it.</p>
  
  <p>Is this possible to do?</p>