title: Java date comparator issue
body: <p>I'm having issues sorting out my comparator by dates. The date format should be in "dd/MM/yyyy" So I call in my information from an SQL Database and then convert strings to date by doing this:</p>
  
  <pre><code>  public void setDeadlineDate(String deadDate) throws ParseException {
          this.d_date = deadDate;
          //convert strings to dates
          formatter = new SimpleDateFormat("dd/MM/yyyy");
          convertedDeadlineDate = (Date)formatter.parse(deadDate);
      }
  </code></pre>
  
  <p>I then make a get method below to call for my comparator. I have to examples but there is always a discrepancy in regards to an odd date being out of place and the comparing not being right.</p>
  
  <p>Example 1:</p>
  
  <pre><code>  @Override
      public int compare(JobRequest j1, JobRequest j2) {
  
          if (j1.getConvertedDeadlineDate().before(j2.getConvertedDeadlineDate())) {
              return -1;
          } else if (j1.getConvertedDeadlineDate().after(j2.getConvertedDeadlineDate())) {
              return 1;
          } 
          else {
              return 0;
          }
      } 
  </code></pre>
  
  <p>Example 2:</p>
  
  <pre><code>public int compare(JobRequest j1, JobRequest j2){
  return j1.getConvertedDeadlineDate().compareTo(j2.getConvertedDeadlineDate());
  }
  </code></pre>
  
  <p>both these examples give me issues and my priorityqueue deadlinedate not to be in the correct order as I would like.
  in my db they are saved as a varchar in the following format "01/12/2012" , 1st december 2012 as it wouldnt let me use their date function to have it in the english format.</p>
  
  <p>is their a better way for me to convert strings and then compare or am i missing something?</p>
  
  <p>thanks</p>
  
  <p>EDIT:
  output getting for ordered dates:</p>
  
  <ul>
  <li>05/04/2011 </li>
  <li>16/12/2012</li>
  <li>18/06/2012</li>
  <li>17/12/2013</li>
  <li>17/12/2013</li>
  <li>16/12/2013</li>
  <li>17/12/2013</li>
  <li>14/08/2012</li>
  <li>19/12/2013</li>
  </ul>
  
  <p>Where I declare PriortyQueue:</p>
  
  <pre><code>private Comparator&lt;JobRequest&gt; comparator = new JobQueueComparator(); //calls my comparator
      private PriorityQueue&lt; JobRequest&gt; scheduledJobs = new PriorityQueue&lt;JobRequest&gt;(100, comparator);
  
      public void addJob(JobRequest job) {
          // now add job to priority queue
          scheduledJobs.add(job); // add jobs from the resultset into queue
      }  
  </code></pre>
  
  <p>scheduledJobs.add(job) just populates the queue from a resultset and keeps adding to queue until all fields in database have been read, see below</p>
  
  <pre><code>public void populateQueueFromDB() {
          // create priority queue
          try {
              String url = "jdbc:mysql://localhost:3306/project";
              Connection conn = DriverManager.getConnection(url, "root", "nbuser");
  
              PreparedStatement stmt = conn.prepareStatement("SELECT user_id,s_date,e_date,d_date,department,projectname,projectapplication,priority,cores,disk_space,analysis FROM booking");
              ResultSet rs;
              rs = stmt.executeQuery();
  
  
              //List&lt;JobRequest&gt; jobList = new ArrayList&lt;JobRequest&gt;();
  
              while (rs.next()) {
                  JobRequest job = new JobRequest();
                  User user = new User();
                  user.setUserID(rs.getString("user_id"));
                  job.setUserID(user.getUserID()); // changes the /user id to the job.setuser id so can call for my queue print.
                  job.setStartDate(rs.getString("s_date"));
                  job.setEndDate(rs.getString("e_date"));
                  job.setDeadlineDate(rs.getString("d_date"));
                  job.setDepartment(rs.getString("department"));
                  job.setProjectName(rs.getString("projectname"));
                  job.setProjectApplication(rs.getString("projectapplication"));
                  job.setPriority(rs.getInt("priority"));
                  job.setCores(rs.getInt("cores"));
                  job.setDiskSpace(rs.getInt("disk_space"));
                  job.setAnalysis(rs.getString("analysis"));
  
                  schedulerPriorityQueue.addJob( job );
  
              }
              schedulerPriorityQueue.printQueue();
  
              conn.close();
  
          } catch (Exception e) {
              System.err.println("Got an exception! ");
              System.err.println(e.getMessage());
          }
  
      }
  
  }
  </code></pre>
  
  <p>PRINT QUEUE:</p>
  
  <pre><code>public void printQueue() {
          for (JobRequest jr : scheduledJobs) {
  
              System.out.print(jr.getUserID() + "--&gt;");
              System.out.print(jr.getStartDate() + "--START--&gt;");
              System.out.print(jr.getEndDate() + "---END--&gt;");
              System.out.print(jr.getDeadDate() + "--DROP--&gt;");
              System.out.print(jr.getDepartment() + "--&gt;");
              System.out.print(jr.getProjectName() + "--&gt;");
              System.out.print(jr.getProjectApplication() + "--&gt;");
              System.out.print(jr.getPriority() + "--PRIORITY--&gt;");
              System.out.print(jr.getCores() + "--&gt;");
              System.out.print(jr.getDiskSpace() + "--&gt;");
              System.out.println(jr.getAnaylsis());
  
          }
      }
  </code></pre>