2017-08-20 75 views
0

我有一個登錄活動,可以讓我在SQLite數據庫中插入我的登錄名和密碼令牌,我想進行另一個名爲config的活動,讓我更改密碼!所以我做了這個方法,但我不知道如何在我的配置活動中使用它。從另一個活動更新android工作室的密碼

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

您的更新查詢有問題。首先,你應該使用準備好的語句。除此之外,'WHERE'子句應該檢查用戶名或用戶ID,而不是以前的密碼。現在,您將更新碰巧擁有相同舊密碼的每條記錄。 –

+0

public void update_user(String old_email,String new_PASS) this.getWritableDatabase()。execSQL(「UPDATE TABLE_USER SET COLUMN_USER_PASSWORD ='」+ new_PASS +「'WHERE COLUMN_USER_Email ='」+ old_email +「'」); }你的意思是這樣嗎? – imen

回答

相關問題