title: java sql - insert timestamp into sql database
body: <p>I'm trying to insert a timestamp into a database, but my code throws an exception, which tells me it's something with my sql statement.</p>
  
  <p>The exception message shown is:</p>
  
  <blockquote>
    <p>"Fout in Rit_ToevoegenController.okKnop(): SQLException in RitDB.voegRitToe() - statement"</p>
  </blockquote>
  
  <p>okKnop is a different method that calls voegRitToe().</p>
  
  <p>The type of the column called 'starttijd' is TIMESTAMP, and the DB Data type is DateTime.</p>
  
  <p>i'm fairly certain that it's the timestamp that causes problems, because the other 2 are just a String and an int.</p>
  
  <p>Any help with making it work would be greatly appreciated. I need to insert both the time and date into the database for comparing later.</p>
  
  <pre><code>public void voegRitToe(Rit r) throws DBException{
      Timestamp starttijd = new Timestamp(System.currentTimeMillis());
      //Date date = new Date(starttijd.getTime());
  
      try(Connection conn = ConnectionManager.getConnection();){
          try(PreparedStatement stmt = conn.prepareStatement("insert into rit(starttijd, lid_rijksregisternummer, fiets_registratienummer) values(?,?,?)");){
              stmt.setTimestamp(1, starttijd);
              stmt.setString(2, r.getLid().getRegisterNr());
              stmt.setInt(3, r.getFiets().getRegisNr());
              stmt.execute();
          }
          catch(SQLException sqlEx){
              throw new DBException("SQLException in RitDB.voegRitToe() - statement");
          }
  
      }
      catch(SQLException sqlEx){
          throw new DBException("SQLException in RitDB.voegRitToe() - verbinding");
      }
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/Jj8aj.png" alt="enter image description here"></p>