Java – when running updates on SQLite, “there are no such columns”
•
Java
I'm trying to update a row in the database This is the code I'm trying to update:
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); }
When I run this command, it throws this error:
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
This is 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);";
Why throw a query? I thought everything I was doing was right
Solution
In your code, you need to add single quotes:
String query = "UPDATE " + TABLE_FB_Feed + " SET " + COL_FB_COMMENTS +"="+"'HELLO'" + " WHERE " + COL_FB_ID+"="+id
or
String query = "UPDATE " + TABLE_FB_Feed + " SET " + COL_FB_COMMENTS +"='HELLO' WHERE " + COL_FB_ID+"="+id
This is another example
"UPDATE DB_TABLE SET YOUR_COLUMN='newValue' WHERE id=myidValue");
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码