0
I intend to save a residence in my database via java when one of the searched parameters is NULL
, but it turns out I can’t find a way to pass that 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;
}
In SQL, every comparison with
NULL
will return false. In case, you need to check if the date is null:data_saida IS NULL
– Jefferson Quesado