2013-08-16 37 views
0

嗨我想更新我的數據庫中的一個條目,我給我的代碼下面的updateEntry函數..我想更新密碼字段我嘗試了一些東西,但它不是工作我想更新我的數據庫中的一個條目

public String updateEntry(String Password) { 
    // Create object of content values 
    ContentValues updatedValues = new ContentValues(); 
    // Assign values for each item 
    // updatedValues.put("USERNAME", User_name); 
    updatedValues.put("PASSWORD", Password); 

    String where = "PASSWORD=?"; 
    db.update("LOGINDETAILS", updatedValues, where, 
      new String[] { Password }); 
    return Password; 
} 

,這是我寫來更新條目代碼:

String Passwordnew =loginDataBaseAdapter.updateEntry(Confirm_password); 
    Passwordnew=Confirm_password; 

,我想更新與confirm_password在DB的密碼。我需要一些好的建議。

+0

歡迎SO。請格式化您的問題,以便我們可以閱讀它,謝謝。 – m0skit0

+0

只是一般性的建議。 java中的變量名稱不要以大寫字母開頭! – bofredo

+0

您代碼中的問題是:您想要更新的條目是什麼?按照你的代碼,你想更新到PASSWORD =密碼?不,這是不正確的。我建議你改變條件來更新正確的條目,也許USERNAME =「what_ever」 – hieuxit

回答

3
public int UpdateContact(int id,String username,String password) { 
    SQLiteDatabase db = this.getWritableDatabase(); 

    ContentValues values = new ContentValues(); 

    values.put(USERNAME, username); 
    values.put(PASSWORD, password); 


    // updating Row 
    return db.update(LOGINDETAILS, values, KEY_ID + " = ?", 
      new String[] { id }); 


} 

調用這個數據庫功能,你的活動

db.UpdateContact("1","dhaval","1234"); 
0
public int updateProfile(GetSet profile) { 
    SQLiteDatabase db = this.getWritableDatabase(); 

    ContentValues values = new ContentValues(); 
    values.put(ID, profile.getUniqueID()); 
    values.put(NAME, profile.getName()); 
    values.put(EMAIL, profile.getEmail()); 
    values.put(DOB, profile.getDob()); 
    values.put(PHONE, profile.getPhone()); 
    values.put(PLACE, profile.getPlace()); 
    // db.close(); 
    // updating row 
    return db.update(TABLE_NAME, values, ID + " = ?", 
      new String[] { profile.getUniqueID() }); 

} 

在相應的活動:

RemoteDatabase remote = new RemoteDatabase(this); 
GetSet profile; 




profile = new GetSet(setname, seteid, setphone, setplace, 
         setdob); 

       profile.setUniqueID(sdumid); 
       remote.updateProfile(profile); 
       remote.close(); 
0

你的邏輯需要更正,不使用密碼的where子句,使用字段是數據庫的主鍵,可能是用戶名或自動增量ID。

然後你就可以更新使用下面的代碼:

public boolean update(int id,String username,String password) 
{ 
    ContentValues cv = new ContentValues(); 
    String where = id+"=?"; 

    cv.put(USERNAME, username); 
    cv.put(PASSWORD, password); 

    return db.update(TABLE_NAME, cv, where,new int[] { id })>0; 
} 
相關問題