My God My God - 6 months ago 24
SQL Question

Update table field value to null programmatically

It is well known that how to set the field value to null by a simple query like -

UPDATE your_table
SET your_column = NULL
WHERE id = 1;

But pro-grammatically, which one is correct way to update the field value to null -

db.execSQL("UPDATE your_table SET your_column='" + null + "WHERE id='" + myid + "'");


db.execSQL("UPDATE your_table SET your_column= NULL WHERE id='" + myid + "'");



I would go with PreparedStatement.

String query="UPDATE  your_table SET your_column= ? WHERE id=?");
PreparedStatement stmnt = conn.prepareStatement(query);
if(colyouAretryingtopass == null){]
  stmnt.setNull(1, Types.VARCHAR);