title: Autocomplete Implementation using Database as the source.
body: <p>I have been trying and searching this for so long, but unable to find the right way of doing this. I have this database from which i want to retrieve some values which will be my auto-complete data source. i have my connection working and i am able to retrieve values in an array which my method is returning. but i am unable to go past this. Please help me out with a jsp page where i can retrieve this array as a json data or can i retrieve this directly and put it in my jsp code as a source for my auto-complete. I can use any framework be it Dojo or J query. Thanks in advance. </p>
  
  <p>populatetextbox.java</p>
  
  <pre><code>package classes.web;
  
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Statement;
  import java.util.ArrayList;
  import java.util.List;
  
  public class PopulateTextbox {
  
      List &lt;String&gt;rowValues = new ArrayList&lt;String&gt;();
      String[] contactListNames; 
      Connection con=null;
      Statement st=null;
      ResultSet rs=null;
  
      public String[] method(){
  
  
          try{
  
  
          String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
          Class.forName(driver);
  
          String db = "jdbc:odbc:Practice_Database";
          con = DriverManager.getConnection(db,"","");
  
          st = con.createStatement();
          String sql = "SELECT Emp_Name FROM EmployeeSearch"; 
          rs = st.executeQuery(sql);
  
          while(rs.next()){
  
              rowValues.add(rs.getString("Emp_Name"));
          }
          contactListNames = (String[]) rowValues.toArray(new String[rowValues.size()]);
  
      }catch(Exception e){System.out.println(e);}
      /*finally{
          try {
                  if(con!=null)con.close();
              } catch (SQLException e) {
  
                  e.printStackTrace();
              }
          try {
              if(rs!=null)rs.close();
          } catch (SQLException e) {
  
              e.printStackTrace();
          }try {
              if(st!=null)st.close();
  
          } catch (SQLException e) {
  
              e.printStackTrace();
          }
  
  
      }*/
          return contactListNames;
  
      }
  }
  </code></pre>