title: How to convert string type (java) and store in date data type in mysql?
body: <p>I want to insert valued from JForm to mysql database. But I can't insert values to date field.. This code is working except for date field. Can someone help me..               </p>
  
  <pre><code>            String s1=txtUsername.getText();
              String s2=txtPassword.getText();
              String s3=txtName.getText();
              String s4=txtAddress.getText();
              String s5=txtContractEndDetails.getText();
  
  
              connection getcon = new connection();
              Connection conn;
  
  
      try{
          conn=getcon.creatConnection();
  
               String sql="insert into TravelGuide(username,password,name,address,contract_end_date)values(?,?,?,?,?)";
  
               PreparedStatement stmt = conn.prepareStatement(sql);
            java.sql.Date dtValue = java.sql.Date.valueOf(s5); 
  
             stmt.setString(1, s1);
  
  
            stmt.setString(2, s2);
  
            stmt.setString(3, s3);
             stmt.setString(4, s4);
  
          stmt.setDate(5, s5);
  
             stmt.executeUpdate();
  
  
  
          }
  
  
      catch(Exception ex){
          JOptionPane.showMessageDialog(PanelTG, ex.getMessage(),"Error Occured 123",2);
      }
  </code></pre>