[英]Update sqlite not working on android
I have a login and reset password activity. 我有一个登录和重置密码活动。 When I enter the new updated password and try to login again, I cannot do so with the new password.
输入新的更新密码并再次尝试登录时,无法使用新密码登录。 Logging in with the old password works fine.
使用旧密码登录可以正常工作。 Basically, the password field is not getting updated/overwritten.
基本上,密码字段不会更新/覆盖。
There is no error in the logcat. logcat中没有错误。 Just that the password is not updated.
只是密码没有更新。
Please help as I am new to android development. 请帮忙,因为我是android开发的新手。
Code for update( DataRegister is the class with GET AND SET functions): 更新代码(DataRegister是具有GET和SET函数的类):
public int updatePassword(DataRegister dataregister) {
db = dbHelper.getWritableDatabase();
ContentValues updated = new ContentValues();
updated.put("PASSWORD", dataregister.getPASSWORD());
return db.update(DataRegister.TABLE, updated, "EMAIL=?" , new String[] {dataregister.getEMAIL()});
}
Code for retrieval: 检索代码:
public String getPass(DataRegister dataRegister) {
db = dbHelper.getWritableDatabase();
Cursor cursor = db.query(DataRegister.TABLE, null, "EMAIL=?",
new String[]{dataRegister.getEMAIL()}, null, null, null, null);
if (cursor != null && cursor.moveToFirst())
{
pass = cursor.getString(cursor.getColumnIndex("PASSWORD"));
cursor.close();
}
return pass;
// return contact
}
Code for Login: 登录代码:
String email = editTextUserName.getText().toString();
dataRegister.setEMAIL(email);
String password = editTextPassword.getText().toString();
dataRegister.setPASSWORD(password);
String storedPassword = loginDataBaseAdapter.getSinlgeEntry(dataRegister);
Toast.makeText(Login.this, storedPassword,Toast.LENGTH_LONG).show();
Boolean a=loginDataBaseAdapter.isExist(dataRegister.getEMAIL());
validation = getSharedPreferences("myShaPreferences", Context.MODE_PRIVATE);
if (password.equals(storedPassword)) {
Toast.makeText(Login.this,
"Congrats: Login Successful", Toast.LENGTH_LONG)
.show();
}
else {
Toast.makeText(Login.this,
"User Name or Password does not match",
Toast.LENGTH_LONG).show();
}
}
});
Code for reset password: 重置密码的代码:
public class ResetPassword extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reset_password);
email = (EditText) findViewById(R.id.em2);
dataRegister=new DataRegister();
loginDataBaseAdapter = new DatabaseAdapter(this);
loginDataBaseAdapter = loginDataBaseAdapter.open();
pass = (EditText) findViewById(R.id.text12);
conpass = (EditText) findViewById(R.id.text13);
email1 = email.getText().toString();
dataRegister.setEMAIL(email1);
pass1 = pass.getText().toString();
conpass1 = conpass.getText().toString();
dataRegister.setPASSWORD(conpass1);
Button btnReset = (Button) findViewById(R.id.btnReset);
btnReset.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (pass1.equals(conpass1)) {
loginDataBaseAdapter.updatePassword(email1,pass1);
String newpass =loginDataBaseAdapter.getPass(dataRegister);
I don't have enough reputation for comment so I will write my suggestion as answer...sorry for that 我没有足够的声誉来发表评论,所以我将我的建议写为答案...很抱歉
I think it will help for u 我认为这对你有帮助
In your getPass method 在您的getPass方法中
if (cursor != null)
cursor.moveToFirst()
pass = cursor.getString(cursor.getColumnIndex("PASSWORD"));
cursor.close();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.