How can I update my sqlite db column "password" by using my sqlite db column "name"??
My sqlite Table:
// Login Table Columns names
private static final String KEY_ID = "id";
public static final String KEY_NAME = "name";
protected static final String KEY_EMAIL = "email";
protected static final String KEY_PASSWORD = "password";
private static final String CREATE_LOGIN_TABLE = "CREATE TABLE " + TABLE_LOGIN + "("
+ KEY_ID + " INTEGER PRIMARY KEY, " + KEY_NAME + " TEXT, "
+ KEY_EMAIL + " TEXT, " + KEY_PASSWORD + " TEXT "
+ ");";
My dbhelper:
// Updating the password database
public int updatePassword(String name,String newpassword) {
db = mSQLiteHandler.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(SQLiteHandler.KEY_PASSWORD, newpassword);
String selection = SQLiteHandler.KEY_NAME+" =? ";
String args[] = {name};
int count = db.update(SQLiteHandler.TABLE_LOGIN ,values, selection, args);
return count;
}
My activity: I want to take my Name from db and select particular row of my password and update that password with Newpassword. "Several times"
btSubmit = (Button) findViewById(R.id.submitButton);
inputUserName = (EditText) findViewById(R.id.etUserName);
inputNewPassword = (EditText) findViewById(R.id.etNewPassword);
inputConfirmPassword = (EditText) findViewById(R.id.etConfirmPassword);
//Database
db = new UserData(getApplicationContext());
// Progress dialog
pDialog = new ProgressDialog(this);
pDialog.setCancelable(false);
btSubmit.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String username = inputUserName.getText().toString();
String newpassword = inputNewPassword.getText().toString();
String confirmpassword = inputConfirmPassword.getText().toString();
if(newpassword.equals("")&& confirmpassword.equals("")) {
Toast.makeText(getApplicationContext(), "New password or Confirmpassword is empty",
Toast.LENGTH_LONG).show();
return;
}
try {
if (newpassword.length() > 0 == confirmpassword.length()>0){
db = new UserData(ResetActivity.this); //create again database to retrive
db.updatePassword(name,newpassword);
Toast.makeText(getApplicationContext(), "Matched! And Updated", Toast.LENGTH_LONG).show();
Intent i1 = new Intent(ResetActivity.this,
LoginActivity.class);
startActivity(i1);
finish();
}
else {
Toast.makeText(getApplicationContext(), "Invalid ", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Toast.makeText(ResetActivity.this, "Problem occurred",
Toast.LENGTH_LONG).show();
}
}
});
}
Aucun commentaire:
Enregistrer un commentaire