gpt4 book ai didi

java - 在 SQLite 上运行更新时为 "No such column"

转载 作者:太空宇宙 更新时间:2023-11-03 12:18:25 25 4
gpt4 key购买 nike

我正在尝试更新数据库中的一行。这是我尝试用于更新的代码:

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

关于java - 在 SQLite 上运行更新时为 "No such column",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25371274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com