title: java insert null date in mysql with update query
body: <p>I'm working on java app (GUI, JDBC, MySQL) and I have problem which I can't solve.</p>
  
  <p>When I insert data into MySQL DB (there are this data type String, INT, Date), there isn't problem if some fields are empty. That empty fields gets Null into DB. But, when I want to update some row, all date field have to be filled or it is error:</p>
  
  <pre><code>com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect date value: 'null' for column 'rociste_datum' at row 1
  </code></pre>
  
  <p><code>rociste_datum</code> is first date column in DB</p>
  
  <p>There are parts of the code:</p>
  
  <p>Code for insert method</p>
  
  <pre><code>    public void insertPredmetDB(String prezime, String ime, int nasBroj, Date datumRocista) {
          if (datumRocista == null || datumRocista.equals("")) {
              datumRocistaDB = null;
          } else {
              String datumRocistaSt = new SimpleDateFormat("yyyy-MM-dd").format(datumRocista);
              datumRocistaDB = java.sql.Date.valueOf(datumRocistaSt);
          }
  </code></pre>
  
  <p>Code for update method</p>
  
  <pre><code>public void updatePredmetDB(int idNovo, String novoPrezime, String novoIme, int noviNasBroj, Date noviRocisteDatum) {
      if (noviRocisteDatum == null || noviRocisteDatum.equals("")) {
          noviRocisteDatumDB = null;
      } else {
          String datumRocistaSt = new SimpleDateFormat("yyyy-MM-dd").format(noviRocisteDatum);
          noviRocisteDatumDB = java.sql.Date.valueOf(datumRocistaSt);
      }
      String izmena = "UPDATE predmeti SET prezime='" + novoPrezime + "', ime='" + novoIme + "', nas_broj='" + noviNasBroj + "', rociste_datum='" + noviRocisteDatumDB + "'where id='" + idNovo + "'";
  
      try {
  
          PreparedStatement ps = con.prepareStatement(izmena);
  
          ps.execute();
  
      } catch (SQLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>For all this dates there are if else statements, and this objects are passing through controller with singleton pattern. I think that it is not necessary to put that code here because there are no errors, and everything works fine, except this dates.</p>
  
  <p>I think that there is a problem with date conversion. Could you give me any help?</p>