title: passing Date parameter to create date range query
body: <p>Using the codes below I would like to ask how can I pass a "Date" parameter coming from a text field. I am planning to create a simple date range query using DAO and servlet. I can display all columns using this codes however I want to filter in using Date...</p>
  
  <p>here's my code:</p>
  
  <pre><code>My Servlet
  
  
  
  
  package source;
  
  import java.io.*;
  import java.sql.SQLException;
  import java.util.*;
  import javax.servlet.ServletException;
  import javax.servlet.http.*;
  
  /**
   *
   * @author jaypee.martinez
   */
  public class parseServlet extends HttpServlet {
  
      private parseDAO parseDAO;
  
  
      @Override
      public void init() throws ServletException {
          String driver = "org.postgresql.Driver";
          String url = "jdbc:postgresql://localhost5432/mydb";
          String username = "postgres";
          String password = "secret";
  
  
          Database database = new Database(driver, url, username, password);
          this.parseDAO = new parseDAO(database);
      }
  
  
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
  
  
              try {
  
              List&lt;parseBean&gt; parse_array = parseDAO.results();
  
              request.setAttribute("parse_array", parse_array);
              request.getRequestDispatcher("results.jsp").forward(request, response);
          }
              catch (SQLException e) {
              throw new ServletException("Cannot retrieve areas", e);
          }
      }
  
  }
  </code></pre>
  
  <p>and My DAO</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  
  package source;
  
  import java.sql.*;
  import java.sql.SQLException;
  import java.text.ParseException;
  import java.text.SimpleDateFormat;
  import java.util.*;
  
  public class parseDAO {
  
      private Database database;
  
      public parseDAO(Database database) {
          this.database = database;
      }
  
      public List&lt;parseBean&gt; results() throws SQLException {
          Connection connection = null;
          PreparedStatement statement = null;
          ResultSet resultSet = null;
          List&lt;parseBean&gt; parse_array = new ArrayList&lt;parseBean&gt;();
          SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd");
  
          try {
              connection = database.getConnection();
              statement = connection.prepareStatement("select * from dateparse");
  
  
              resultSet = statement.executeQuery();
  
  
              while (resultSet.next()) {
                  parseBean parsearray = new parseBean();
                  parsearray.setDate(resultSet.getDate("date"));
                  parsearray.setName(resultSet.getString("name"));
                  parsearray.setAddress(resultSet.getString("address"));
                  parse_array.add(parsearray);
              }
          } finally {
              if (resultSet != null) try { resultSet.close(); } catch (SQLException logOrIgnore) {}
              if (statement != null) try { statement.close(); } catch (SQLException logOrIgnore) {}
              if (connection != null) try { connection.close(); } catch (SQLException logOrIgnore) {}
          }
  
          return parse_array;
      }
  }
  </code></pre>