SQLiteLog:(1)near" *":语法错误

时间:2015-03-09 10:38:17

标签: java android sql database sqlite

我在下面的代码中获取SQLiteLog﹕ (1) near "*": syntax error,同时从table中删除行。代码出错了,为什么我收到此错误?

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

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

4 个答案:

答案 0 :(得分:4)

它应该是"Delete from........"而不是"Delete * from........"。因为你已经出现了语法问题

答案 1 :(得分:2)

single quote (')中传递值并从查询中删除*

最后:

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

答案 2 :(得分:1)

从查询中删除*

更新代码

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

Documentation

答案 3 :(得分:0)

DELETE不需要星号。事实上,它是无效的。 DELETE FROM函数将删除整行。无法指定要删除的列,因为该子句只能删除整行。

你无法真正删除'一个细胞。您可以设置为空('')或NULL

如果您需要专门编辑某些列的内容,我建议使用UPDATE table SET a = 'b' WHERE id = 'some number'子句