これは私の最近の質問に関連しています...
この状況では、DAO とサーブレットがあり、日付 (event_date) をパラメーターとしてクエリに渡したいと考えています。どこでそれを行うことができますか?
私のサーブレットの一部
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-DD");
String username = request.getParameter("username");
String name = request.getParameter("name");
String dateto = request.getParameter("dateto");
try
{
List prodlistsearch_array = this.pdtDAO.prodlistsearch(name);
request.setAttribute("prodlistsearch_array", prodlistsearch_array);
request.getRequestDispatcher("events_audit.jsp").forward(request, response);
} catch (SQLException e) {
throw new ServletException("Cannot retrieve areas", e);
}
私のDAOの一部
public List<pdtBean> prodlistsearch(String name) throws SQLException{
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
String querystring = "select * from mydb where name = ? and event_date between ? and ?";
List<pdtBean> prodlistsearch_array = new ArrayList<pdtBean>();
try {
connection = database.getConnection();
statement = connection.prepareStatement(querystring);
statement.setString(1, name);
resultSet = statement.executeQuery();
while (resultSet.next()) {
pdtBean prodlistsearcharray = new pdtBean();
prodlistsearcharray.setId(resultSet.getString("id"));
prodlistsearcharray.setEvent_date(resultSet.getString("event_date"));
prodlistsearcharray.setTitle(resultSet.getString("title"));
prodlistsearch_array.add(prodlistsearcharray);
}
} finally {
try { resultSet.close(); } catch (SQLException logOrIgnore) {}
try { statement.close(); } catch (SQLException logOrIgnore) {}
try { connection.close(); } catch (SQLException logOrIgnore) {}
}
return prodlistsearch_array;
}