“Incorrect datetime” value no MySQL


Hi, I'm trying to insert dates in dd/mm/Y format into two jTextField , in MYSQL, however I get an error message only for the first field:

Incorrect datetime value: '01/01/2016' for function str_to_date

The java code is:

if (novoCadastro) {
                //Cria a String para inserir os dados
                query = "INSERT INTO Clientes(Nome,Endereço,Cidade,CPF,TelefoneCliente,EmailCliente,Produto,UltimaCompra,ClienteDesde) VALUES(?,?,?,?,?,?,?,DATE_FORMAT(STR_TO_DATE(?, '%dd/%mm/%Y'),'%d-%m-%Y'),DATE_FORMAT(STR_TO_DATE(?,'%dd/%mm/%Y'),'%d-%m-%Y'))";
            //Seta os valores na String de inserção
            stmt = con.prepareStatement(query);
            stmt.setString(1, txtNome.getText());
            stmt.setString(2, txtEndereco.getText());
            stmt.setString(3, txtCidade.getText());
            stmt.setString(4, txtCPF.getText());
            stmt.setString(5, txtTelefone.getText());
            stmt.setString(6, txtEmail.getText());
            stmt.setString(7, txtProduto.getText());
            stmt.setString(8, txtUltComp.getText());
            stmt.setString(9, txtClienDesd.getText());
            JOptionPane.showMessageDialog(null, "Cadastro realizado com sucesso! ");


According to the documentation regarding date formatting , a %d already represents the two digits of the day of the month. Similarly, %m already represents the two digits referring to the month itself.

That way, instead of

STR_TO_DATE(?, '%dd/%mm/%Y')


STR_TO_DATE(?, '%d/%m/%Y')
Scroll to Top