title: Data truncation: Incorrect datetime value: ''
body: <p>Can anyone help me with a sample JSP code to store date in a MySql database through JDBC?
  When I try to execute the code given below, I get the following exception:</p>
  
  <blockquote>
    <p>com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect datetime value: '' for column 'date' at row 1</p>
  </blockquote>
  
  <p>How to overcome this problem? Following is my code:</p>
  
  <pre><code>Connection con = null;
  
  String StaffName = request.getParameter("StaffName");
  // String subcode = request.getParameter("subcode");
  String hourId = request.getParameter("hourId");
  if (hourId == null)
      hourId = "";
  String day = request.getParameter("day");
  if (day == null)
      day = "";
  String date = request.getParameter("date");
  try {
      Class.forName("com.mysql.jdbc.Driver");
      con = DriverManager.getConnection("jdbc:mysql://localhost:3306/StaffAllocation", "root", "success");
  
      // PreparedStatement stat = con.PrepareStatement();
      String updateString = "INSERT INTO tblstaffallocation (StaffName,hourId,daysId,date) VALUES (?,?,?,?)";
      PreparedStatement preparedStatement = con.prepareStatement(updateString);
  
      preparedStatement.setString(1, StaffName);
      preparedStatement.setInt(2, 0);
      preparedStatement.setInt(3, 0);
      preparedStatement.setString(4, date);
  } catch (Exception e) {
      out.print(e);
  }
  </code></pre>