加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 04:21:56 所属栏目:Java 来源:网络整理
导读:我正在尝试更新数据库中的一行.这是我试图用来更新的代码: public void addFBComments(int id){ SQLiteDatabase db = this.getWritableDatabase(); String query = "UPDATE " + TABLE_FB_FEED + " SET " + COL_FB_COMMENTS+"="+"HELLO" + " WHERE " + COL_F
我正在尝试更新数据库中的一行.这是我试图用来更新的代码:

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");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读