我面临一个非常烦人的错误,就是它不断向第一列输入0
,然后输入其余的值。
这是我的代码:
System.out.println(forename);
String statement = "UPDATE " + USER_TABLE + " SET " + FORENAME + " = " + "'" + forename + "'"
+ " AND " + SURNAME + " = " + "'" + surname + "'" + " AND " + EMAIL + " = " + "'" + email + "'"
+ "WHERE " + USER_ID + " = " + userID;
sqLiteDatabase.execSQL(statement);
因此,如果forename为Luke
,它将打印Luke
,但在运行此查询后,表格将如下所示:
UserID | Forename | Surname | Email
____________________________________________
1 0 Smith luke@s.com
正如您所看到的那样Luke
未放入Forename
字段,尽管我可以清楚地看到Luke
LogCat
答案 0 :(得分:1)
应该使用ContentValues
执行此任务:
例如:
SQLiteDatabase database = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(FORENAME, forename);
values.put(SURNAME, surname);
values.put(EMAIL, email);
database.update(USER_TABLE, values, USER_ID + "=?", new String[] {userID});
database.close();
return true;