简体   繁体   中英

SQLiteLog﹕ (1) near “*”: syntax error

I am getting SQLiteLog﹕ (1) near "*": syntax error in the below code while deleting row from table.Whats wrong with the code and why i am getting this error?

 public void deleteVideo(String key){
            String selectQuery = "DELETE  * FROM " + TABLE_TOW + " WHERE " + KEY_ID + "= '"+key;

            SQLiteDatabase db = this.getWritableDatabase();
            db.rawQuery(selectQuery, null);
        }

It should be "Delete from........" and not "Delete * from........" . Because you have made a syntax issue

Pass value in single quote (') and remove * from query

Final:

String selectQuery = "DELETE FROM " + TABLE_TOW + " WHERE " + KEY_ID + "='"+key+"'";

Remove * from your query.

Updated Code

public void deleteVideo(String key){
    String selectQuery = "DELETE  FROM " + TABLE_TOW + " WHERE " + KEY_ID + "= '"+key+"'";
    SQLiteDatabase db = this.getWritableDatabase();
    db.rawQuery(selectQuery, null);
}

Documentation

The asterisk isn't necessary with DELETE . In fact, it's invalid. The DELETE FROM function will delete the entire row. There is no way to specify which columns are to be deleted, because the clause can only delete entire rows.

You can't really 'delete' a cell. You can set to be empty ( '' ), or NULL .

If you need to specifically edit the contents of certain columns I recommend the UPDATE table SET a = 'b' WHERE id = 'some number' clause

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM