Android 我想更新数据库中的一个条目

Android 我想更新数据库中的一个条目,android,database,sqlite,Android,Database,Sqlite,您好,我想更新数据库中的一个条目,我正在为下面的updateEntry函数提供代码。我想更新密码字段。我尝试了一些操作,但它不起作用 public String updateEntry(String Password) { // Create object of content values ContentValues updatedValues = new ContentValues(); // Assign values for each item // u

您好,我想更新数据库中的一个条目,我正在为下面的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;
我想用确认密码更新数据库中的密码。我需要一些好的建议

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");
将此数据库函数调用到您的活动

db.UpdateContact("1","dhaval","1234");
在相应的活动中:

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




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

                profile.setUniqueID(sdumid);
                remote.updateProfile(profile);
                remote.close();
在相应的活动中:

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




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

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

您的逻辑需要更正,不要对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;
 }

您的逻辑需要更正,不要对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;
 }

欢迎来到SO。请将您的问题格式化,以便我们阅读,谢谢。只是一个一般性建议。java中的变量名从不以大写字母开头!代码中的问题是:要更新的条目是什么?按照你的代码,你想更新到PASSWORD=PASSWORD???不,不正确。我建议您更改where条件以更新正确的条目,可能是USERNAME=“what\u ever”欢迎使用SO。请将您的问题格式化,以便我们阅读,谢谢。只是一个一般性建议。java中的变量名从不以大写字母开头!代码中的问题是:要更新的条目是什么?按照你的代码,你想更新到PASSWORD=PASSWORD???不,不正确。我建议您更改where条件以更新正确的条目,可能是USERNAME=“what\u ever”