目前我有一個只有一行的表,我想更新該行的某些列。insert 方法被正確執(zhí)行,而 update 返回一個 id = 0 并且打印用戶名始終是以前的用戶名并且沒有更新。@Overridepublic void onCreate(SQLiteDatabase db) { db.execSQL("create table "+TABLE_NAME1+" (ID INTEGER PRIMARY KEY AUTOINCREMENT, USERNAME TEXT, WON INT, DRAW INT, LOST INT, CELLSNUMBER INT,RESULT INT)"); }public boolean addUserInformation(String name, int w, int l, int d, boolean firstTime){ SQLiteDatabase db = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(USERNAME, name); values.put(WIN, w); values.put(LOST, l); values.put(DRAW, d); long id = 0; if(firstTime == true ) { id = db.insert(TABLE_NAME1, null, values); } if(firstTime == false){ id=db.update(TABLE_NAME1, values, "USERNAME = ? and WON = ? and DRAW = ? and LOST = ?",new String[] { name, String.valueOf(w), String.valueOf(d), String.valueOf(l) }); } if(id == -1) return false; else return true; }
如何在 SQLite 中更新單行的多列?
婷婷同學(xué)_
2023-02-23 14:47:25