title: How to write a MySQL query in Java with user parameters with dates
body: <p>First of all guys thanks for the previous help and advice. I am only learning databases and MySQL, so please bear with me while I ask so major newbie type questions.</p>
  
  <p>I'm entering 2 parameters, one is a string and the other is a date. I then want to then output of a another value. The string is straight forward but I'm unable to compare the dates properly. If the dates and the strings match then that is the record I'm looking for  </p>
  
  <p>Here is a copy of the table</p>
  
  <pre><code>    private String agentDetail = "CREATE TABLE AgentDetail (" 
          + "idNo INT(64) NOT NULL AUTO_INCREMENT,"  
          + "initials VARCHAR(2)," 
          + "agentDate DATE,"  
          + "agentCount INT(64), "
          + "PRIMARY KEY(idNo))"; 
  </code></pre>
  
  <p>The problem is that it always brings back all the dates, both the correct and incorrect results</p>
  
  <p>and here is the code that I am currently using</p>
  
  <pre><code>    protected void getAgentIdNo (Connection con, PreparedStatement preStatement,
                  ResultSet result, String initials, Date myDate) {
          try {
              preStatement = con.prepareStatement("SELECT * FROM AGENTDETAIL");
              result = preStatement.executeQuery();
  
              while (result.next()) {
                  if (result.getString("initials").equals(initials)){
                      if (myDate.compareTo(result.getDate("agentDate")) == 0){
                          System.out.println("The date and initials matched !!");
                          System.out.println("The id no is " + result.getint("idNo");
                      }
                  }
              }
          }
  
          catch (SQLException ex) {
              System.out.println("An error occured when reading from the data base");
              ex.printStackTrace();
          }
      }
  </code></pre>
  
  <p>I also know that this code is far from perfect so feel to suggest a more professional looking code.
  Thanks in advance for any all help and support.</p>