我试图通过我的SQLiteHelper类中的此方法更新我的SQLite数据库,我收到错误:
android.database.sqlite.SQLiteException: unrecognized token: "55c7e253afcf48" (code 1): , while compiling: UPDATE login SET user_group=? WHERE uid=55c7e253afcf48.85187730
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
Run Code Online (Sandbox Code Playgroud)
除了额外的".85187730"之外,uid是正确的......我不确定这些数字是什么意思.这是我的更新方法:
//updating sqlite database with the group name
public void updateUserGroup(String groupName) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_GROUP, groupName);
HashMap<String, String> user = getUserDetails();
String userID = user.get("uid");
System.out.println("User id is: " + userID);
db.update(TABLE_LOGIN, values, SQLiteHandler.KEY_UID + "=" + "userID", null);
}
/**
* Getting user data from database
* */
public HashMap<String, String> getUserDetails() {
HashMap<String, String> user = new HashMap<String, String>();
String selectQuery = "SELECT * FROM " + TABLE_LOGIN;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// Move to first row
cursor.moveToFirst();
if (cursor.getCount() > 0) {
user.put("name", cursor.getString(1));
user.put("email", cursor.getString(2));
user.put("user_group", cursor.getString(3));
user.put("uid", cursor.getString(4));
user.put("created_at", cursor.getString(5));
}
cursor.close();
//db.close();
// return user
Log.d(TAG, "Fetching user from Sqlite: " + user.toString());
return user;
}
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏.
你错过了引号uid.
您应该传递每个字符串,以避免错误.
UPDATE login SET user_group=? WHERE uid="55c7e253afcf48.85187730"
Run Code Online (Sandbox Code Playgroud)
在你的情况下查询将是
HashMap<String, String> user = getUserDetails();
String userID = user.get("uid");
db.update(TABLE_LOGIN, values, SQLiteHandler.KEY_UID + "=\"" + userID + "\"", null);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6990 次 |
| 最近记录: |