java – 在SQLite上运行更新时“没有这样的列”

我正在尝试更新数据库中的一行.这是我试图用来更新的代码

public void addFBComments(int id){ 
    sqliteDatabase db = this.getWritableDatabase(); 
    String query = "UPDATE " + TABLE_FB_Feed + " SET " + COL_FB_COMMENTS+"="+"HELLO" + " WHERE " + COL_FB_ID+"="+id;

    db.execsql(query);
}

当我运行该命令时,它会抛出此错误

08-18 15:42:10.145: E/AndroidRuntime(10493): FATAL EXCEPTION: Thread-922
08-18 15:42:10.145: E/AndroidRuntime(10493): android.database.sqlite.sqliteException: no such column: HELLO (code 1): , while compiling: UPDATE fb_Feed SET fb_comments= HELLO  WHERE _id=3

这是TABLE_FB_Feed

private static final String TABLE_FB_Feed_CREATE = "create table " + TABLE_FB_Feed + 
" ("
        + COL_FB_ID + " integer primary key autoincrement not null," 
        + COL_FB_MESSAGE + " text," 
        + COL_FB_CAPTION + " text,"
        + COL_FB_POSTER_ID + " text,"
        + COL_FB_POST_ID + " text,"
        + COL_FB_LIKES + " text,"
        + COL_FB_POSTER_NAME + " text,"
        + COL_FB_COMMENTS + " text," // this is the column i want to update
        + COL_FB_LIKES_NUM + " text,"
        + COL_FB_TIMESTAMP + " text,"
        + COL_FB_PROFILE_PICTURE_URI + " text,"
        + COL_FB_PICTURE_URI + " text," 
        + COL_FB_NAME + " text," 
        + COL_FB_PREVIoUS_PAGE_URI + " text,"
        + COL_FB_NEXT_PAGE_URI + " text," 
        + COL_FB_POST_TYPE + " text," 
        + COL_FB_LINK_NAME + " text," 
        + COL_FB_COMMENTS_NUM + " text," 
        + COL_FB_STORY + " text," 
        + COL_FB_DESCRIPTION + " text,"
        + COL_FB_COMMENTS_BEFORE + " text,"
        + COL_FB_COMMENTS_AFTER + " text,"
        + COL_FB_LIKES_PROFILE_PIC + " text,"
        + COL_FB_COMMENTS_PROFILE_PIC + " text);";

为什么抛出查询?我以为我正在做的一切都正确.

解决方法:

在您的代码中,您需要添加单引号:

String query = "UPDATE " + TABLE_FB_Feed + " SET " + COL_FB_COMMENTS
    +"="+"'HELLO'" + " WHERE " + COL_FB_ID+"="+id

要么

String query = "UPDATE " + TABLE_FB_Feed + " SET " + COL_FB_COMMENTS
    +"='HELLO' WHERE " + COL_FB_ID+"="+id

这是另一个例子

"UPDATE DB_TABLE SET YOUR_COLUMN='newValue' WHERE id=myidValue");

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能