从另一个活动更新android studio中的密码

时间:2017-08-20 23:51:59

标签: android sqlite

我有一个登录活动,让我在SQLite数据库中插入我的登录名和密码令牌,我想创建另一个名为config的活动,让我更改密码!所以我制作了这个方法,但我不知道在配置活动中如何使用它。

 public class DatabaseHelper extends SQLiteOpenHelper {
//Database Version
private static final int DATABASE_VERSION = 1;

// Database Name
private static final String DATABASE_NAME = "UserManager.db";

// User table name
private static final String TABLE_USER = "user";

// User Table Columns names
private static final String COLUMN_USER_ID = "user_id";
private static final String COLUMN_USER_NAME = "user_name";
private static final String COLUMN_USER_EMAIL = "user_email";
private static final String COLUMN_USER_PASSWORD = "user_password";

// create table sql query
private String CREATE_USER_TABLE = "CREATE TABLE " + TABLE_USER + "("
        + COLUMN_USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + COLUMN_USER_NAME + " TEXT,"
        + COLUMN_USER_EMAIL + " TEXT," + COLUMN_USER_PASSWORD + " TEXT" + ")";

// drop table sql query
private String DROP_USER_TABLE = "DROP TABLE IF EXISTS " + TABLE_USER;

  public DatabaseHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(CREATE_USER_TABLE);
}
  @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    //Drop User Table if exist
    db.execSQL(DROP_USER_TABLE);

    // Create tables again
    onCreate(db);

}

 public void update_user (String old_PASS , String new_PASS )
{
 this.getWritableDatabase().execSQL("UPDATE TABLE_USER SET COLUMN_USER_PASSWORD='"+new_PASS+ "' WHERE COLUMN_USER_PASSWORD= '"+old_PASS+"'" );
}

1 个答案:

答案 0 :(得分:0)

DatabaseHelper db = new DatabaseHelper(this);
db.update_user("your old password", "your new password");

最好从教程中学习如何使用android数据库。

https://www.androidhive.info/2011/11/android-sqlite-database-tutorial/