title: How to insert Date into MySQL Database table in Java?
body: <p>How do I insert date, without time, to MySQL database table?
  I tried these codes but I get the following exception:</p>
  
  <pre><code>com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Mar 05 00:00:00 GMT-08:00 2014,1,1)' at line 1
  </code></pre>
  
  <p>NOTE: In MySQL table, data type of this column I chose date datatype </p>
  
  <pre><code>String Date = "\\d\\d\\d\\d\\D[0-1][0-9]\\D[0-3][0-9]";
  while (DateMatcher.find())  {   
      String date = DateMatcher.group().trim();
  
      DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
      Date myDate = formatter.parse(date);
  
      db.insert_date(myDate,2,1);           
  }
  </code></pre>
  
  <p>I've problem only with date part
  Query for inserting Date :</p>
  
  <pre><code>// insert DATE
  public void insert_date(Date  date_str, int sentence_id ,int document_id ){
         // Statements allow to issue SQL queries to the database
  
      try {
          statement = connect.createStatement();
  
          System.out.println(  "insert into Date(date_Str,Sen_id,doc_id) " +
                   " values(" + date_str + "," +  sentence_id + "," + document_id +  ")"
                   );
  
  
          statement.executeUpdate(
  
           "insert into test.Date(date,Sen_id,doc_id)" +
           " values(" + date_str + "," +  sentence_id + "," + document_id + ")"
            );
      }
      catch(Exception e ){System.out.println(e);};
      // Result set get the result of the SQL query
  
  }
  </code></pre>