致命 - RuntimeException SQLite从数据库中删除数据

时间:2016-04-25 09:47:16

标签: android sqlite where-clause runtimeexception

我正在尝试从SQLite表中删除数据,其中源列等于"在线"

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.reminders/com.reminders.FetchDataActivity}: android.database.sqlite.SQLiteException: no such column: Online (code 1): , while compiling: delete from ReminderTable where source = Online

这是我的代码:

public void deleteOnlineReminders() {
        SQLiteDatabase db = this.getReadableDatabase();
        db.execSQL("delete from "+ TABLE_REMINDERS + " where " + KEY_SOURCE + " = " + "Online");
    }

Or是否因为我没有任何数据进入表格,其中列来源=在线

3 个答案:

答案 0 :(得分:1)

你必须使用' Online'在你的字符串concat中(注意引号)。

从异常中可以看出,编译语句在引用列而不是字符串时是错误的。

您可能还想为参数使用预准备语句而不是字符串连接: How do I use prepared statements in SQlite in Android?

这是更干净,更安全的版本:)

答案 1 :(得分:1)

试试此代码。

db.execSQL("delete from "+ TABLE_REMINDERS + " where " + KEY_SOURCE + "=?",new String[] { "Online" });

答案 2 :(得分:0)

my_account.get_campaigns()
相关问题