17

I have done this and it is not working. I am getting force close.

public boolean favoriteDelete(int id) {
    return database.delete("FavoriteData", "Google" + "=" + id, null) > 0;
}
Pieter van Niekerk
  • 848
  • 15
  • 42
sai
  • 2,562
  • 8
  • 31
  • 46

5 Answers5

43

You can simply use sql query to delete.

public void delete(String id) {
        db.execSQL("delete from "+TBL_NAME+" where Google='"+id+"'");
    }

In your query you are passing null in place of whereArgs

db.delete(table, whereClause, whereArgs)

It should be like this

db.delete(TBL_NAME, "Google=?", new String[]{Integer.toString(id)});
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
6

Try this

public boolean favoriteDelete(int id) {
    return db.delete(DATABASE_TABLE, KEY_ROWID +  "=" + id, null) > 0;
}
diya
  • 6,938
  • 9
  • 39
  • 55
4
database.delete("tablename", "column_name=?", new String[] {Integer.toString(id)});
  • the where condition values should be given as a string array
AD14
  • 1,218
  • 19
  • 32
1

It's better to use placeholders than string manipulation. Ok for int's but as soon as you put a string in there things will go wrong.

String where = COLUMN_NAME_ADDRESS + " = ?";
String[] whereArgs = { String.valueOf(address) };

SQLiteDatabase db = mDbHelper.getWritableDatabase();
db.delete(TABLE_NAME_DEVICES, where, whereArgs);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Timmmm
  • 88,195
  • 71
  • 364
  • 509
1

add single quotes in your where clause...

return database.delete("FavoriteData", "Goggle" + "='" + id+"'", null) > 0;
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
AAnkit
  • 27,299
  • 12
  • 60
  • 71