title: Passing date type variable as method parameter in java
body: <p>This is in the Main class</p>
  
  <pre><code>    Contest c = new Contest();
      c.setAnnouncementDate("2014-03-02");
      Contest.addContest(c);
  </code></pre>
  
  <p>I am trying to insert this date in my mysql table. But it gives type incompatibility.</p>
  
  <p>So we tried this code:</p>
  
  <pre><code>    Contest c = new Contest();
      SimpleDateFormat f = new SimpleDateFormat("yyyy-mm-dd");
      java.sql.Date da = new java.sql.Date(f.parse("2014-04-02").getTime());
      c.setAnnouncementDate(da);
      Contest.addContest(c);
  </code></pre>
  
  <p>there is a addContest(Contest cont) method in Contest class which is used to insert the dates in mysql table:
  code used is:</p>
  
  <pre><code>    PreparedStatement s = con.prepareStatement("Insert into " + TABLENAME + " ( " +       CONTESTID + " , " + ANNOUNCEMENTDATE + " , " + RESULTDECLARATIONDATE + " , " + SUBMISSIONSTARTDATE + " , " + SUBMISSIONENDDATE + " , " + REWARD + " ) VALUES ( ?,?,?,?,?,?)");
  </code></pre>
  
  <p>we inserted date using :</p>
  
  <pre><code>    s.setDate(2, (java.sql.Date) cont.getAnnouncementDate());
  </code></pre>
  
  <p>here, it always inserts 2014-01-02 date in mysql table, irrespective of our argument that we pass.
  please help me.</p>