Reputation: 367
I am creating a app in which i have used sqlite db.I have successfully created the table and inserted data into it.But when i try to delete the data , the query doesn't seems to be working.
Code
public void deleteSubject(int Id) {
String query = "DELETE FROM " + TABLE_NAME + " WHERE " + DataBaseColumns.SUBJECT_ID + "=" + Id;
// String whereClause = DataBaseColumns.SUBJECT_ID + "=?";
database = openDb();
Cursor cursor = null;
try {
// result = database.delete(TABLE_NAME, whereClause, new String[Id]);
cursor = database.rawQuery(query, null);
} catch (SQLiteException e) {
Log.e("Error in delete Subjects", e.getMessage());
}
database = closeDb();
cursor.close();
}
Upvotes: 1
Views: 741
Reputation: 152807
Use execSQL()
and not rawQuery()
for DELETE
queries.
rawQuery()
only compiles the SQL but does not run it until the cursor is moved. execSQL()
both compiles and runs the SQL.
Upvotes: 6