Search for NULL mysql via Java

0

I want to write a resident in my database via java when one of the searched parameters is NULL , but it turns out I can not figure out how to pass this command.

My code is:

public Usuario registraSaida(String nome) throws SQLException {
    String sql = "UPDATE usuario_acesso SET data_saida = ? WHERE usuario_nome = ? AND data_saida = NULL";
    java.sql.Timestamp date = new java.sql.Timestamp(new java.util.Date().getTime());

    PreparedStatement pst = conexao.prepareStatement(sql);
    pst.setTimestamp(1, date);
    pst.setString(2, nome);
    pst.executeUpdate();

    System.out.println(nome);
    return null;
}
    
asked by anonymous 05.06.2018 / 05:48

1 answer

2

Change the fill from String sql to

String sql = "UPDATE usuario_acesso SET data_saida = ? WHERE usuario_nome = ? AND data_saida IS NULL";

As said in comment, the "comparison" should be done with IS NULL .

    
05.06.2018 / 12:50