SQLite的返回:错误code = 1,味精=接近和QUOT; ......":语法错误味精、错误、语法错误、SQLite

2023-09-04 07:37:23 作者:潇洒的

我想更新sqlite的(机器人)一列,但该日志显示了以下错误。任何人都可以请帮我解决它?

  12月6日至十一日:52:21.373:I /数据库(355):源码返回:错误code = 1,味精=近@gmail:语法错误
12月6号至十一日:52:21.373:E /数据库(355):错误更新密码=使用12345更新用户设置密码=? WHERE COL_USERID = something@gmail.com
12月6号至十一日:52:21.373:D / AndroidRuntime(355):关闭虚拟机
12月6号至十一日:52:21.373:W / dalvikvm(355):主题ID = 1:螺纹退出与未捕获的异常(组= 0x4001d800)
12月6号至十一日:52:21.393:E / AndroidRuntime(355):致命异常:主要
12月6号至十一日:52:21.393:E / AndroidRuntime(355):android.database.sqlite.SQLiteException:近@gmail:语法错误:在编制:更新用户设置密码=? WHERE COL_USERID =东西@ gmail.com
 

和这里是我的code:

 众长updateUserPassword(字符串userid,字符串密码){
    ContentValues​​ initialValues​​ =
            createUserPasswordContentValues​​(密码);

    返回database.update(LOGIN_TABLE,initialValues​​,COL_USERID =+用户ID,NULL);
}

私人ContentValues​​ createUserPasswordContentValues​​(字符串密码){
    ContentValues​​值=新ContentValues​​();
    values​​.put(COL_PASSWORD,密码);
    返回值;
}
 

解决方案

单引号缺失。使用下面code

 返回database.update(LOGIN_TABLE,initialValues​​,COL_USERID ='+用户ID +',NULL);
 
VScode第三方插件打开sqlite数据库

I am trying to update a column in Sqlite (android) but the log shows the following error. Could anyone please help me with solving it?

06-11 12:52:21.373: I/Database(355): sqlite returned: error code = 1, msg = near "@gmail": syntax error
06-11 12:52:21.373: E/Database(355): Error updating password=12345 using UPDATE user SET password=? WHERE COL_USERID = something@gmail.com
06-11 12:52:21.373: D/AndroidRuntime(355): Shutting down VM
06-11 12:52:21.373: W/dalvikvm(355): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-11 12:52:21.393: E/AndroidRuntime(355): FATAL EXCEPTION: main
06-11 12:52:21.393: E/AndroidRuntime(355): android.database.sqlite.SQLiteException: near "@gmail": syntax error: , while compiling: UPDATE user SET password=? WHERE COL_USERID = something @gmail.com

And here is my code:

public long updateUserPassword(String userid, String password) {
    ContentValues initialValues = 
            createUserPasswordContentValues(password);

    return database.update(LOGIN_TABLE, initialValues, "COL_USERID = "+userid, null);
}

private ContentValues createUserPasswordContentValues(String password) {
    ContentValues values = new ContentValues();
    values.put(COL_PASSWORD, password);
    return values;
}

解决方案

Single quotes missing. Use below code

return database.update(LOGIN_TABLE, initialValues, "COL_USERID = '"+userid+ "'", null);