My java code is working, but when adding data to an SQL table, the fields are being filled in as NULL, even though I have added values.
Part of the code where the insert occurs:
public void salvarCliente() throws ClassNotFoundException, SQLException {
Connection conexao = new FabricaDeConexao().retornaConexao();
String query = "INSERT INTO cli(nome,endereco,cpf) values (?,?,?)";
PreparedStatement stmt = conexao.prepareStatement(query);
stmt.setString(1, textFieldNome.getText());
stmt.setString(2, textFieldEndereco.getText());
stmt.setString(3, textFieldCpf.getText());
stmt.executeUpdate();
stmt.close();
conexao.close();
}
NOTE: The code was working correctly. The error started when I added a method of data removal. I used the command:
String query = "delete from cli where id=(select max(id))";
To delete the last record inserted in the table (removed by ID).
Instead of deleting the last record, it erased all the data in the table and from then started to enter the values as NULL.