我正在尝试更新Sqlite(android)中的列,但日志显示以下错误。有人可以帮我解决一下吗?
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
这是我的代码:
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;
}
答案 0 :(得分:2)
缺少单引号。使用以下代码
return database.update(LOGIN_TABLE, initialValues, "COL_USERID = '"+userid+ "'", null);
答案 1 :(得分:1)
替换以下行:
return database.update(LOGIN_TABLE, initialValues, "COL_USERID = '"+userid+"'", null);
而不是:
return database.update(LOGIN_TABLE, initialValues, "COL_USERID = "+userid, null);
答案 2 :(得分:0)
"COL_USERID = "+userid
中缺少单引号,请使用此"COL_USERID = '" + userid + "'"
即
简单地说,改变这个
return database.update(LOGIN_TABLE, initialValues, "COL_USERID = "+userid, null);
到
return database.update(LOGIN_TABLE, initialValues, "COL_USERID = '" + userid + "'", null);