第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用具有信息的現(xiàn)有數(shù)據(jù)庫創(chuàng)建登錄活動(dòng)

如何使用具有信息的現(xiàn)有數(shù)據(jù)庫創(chuàng)建登錄活動(dòng)

幕布斯7119047 2022-07-27 09:10:31
我有現(xiàn)有的數(shù)據(jù)庫,其中包含姓名、姓氏、電子郵件電話和密碼,我想使用它來進(jìn)行具有兩個(gè)編輯文本(電子郵件或電話號(hào)碼)和(密碼)的登錄活動(dòng)。登錄活動(dòng)背后的代碼是什么?登錄(如果成功獲取其他數(shù)據(jù))---->ParentsMenu(使用數(shù)據(jù))DatabaseHelper.javapackage edu.angelo.parentsportal;import android.content.ContentValues;import android.content.Context;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.database.sqlite.SQLiteOpenHelper;import java.util.ArrayList;public class DatabaseHelper extends SQLiteOpenHelper {public static final String DATABASE_NAME = "Parents_Portal.db";public static final String TABLE_NAME = "Parents_Table";public static final String COL_0 = "ID";public static final String COL_1 = "NAME";public static final String COL_2 = "SURNAME";public static final String COL_3 = "EMAIL_ADDRESS";public static final String COL_4 = "PHONE_NUMBER";public static final String COL_5 = "PASSWORD";public DatabaseHelper(Context context) {    super(context, DATABASE_NAME, null, 1);}@Overridepublic void onCreate(SQLiteDatabase db) {db.execSQL("create table " + TABLE_NAME +"(ID INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT, SURNAME TEXT, EMAIL_ADDRESS TEXT, PHONE_NUMBER TEXT, PASSWORD TEXT)");}@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {db.execSQL("DROP TABLE IF EXISTS "+TABLE_NAME);onCreate(db);}public boolean insertData(String name, String surname, String email_address, String phone_number, String password){    SQLiteDatabase db = this.getWritableDatabase();    ContentValues contentValues = new ContentValues();    contentValues.put(COL_1,name);    contentValues.put(COL_2,surname);    contentValues.put(COL_3,email_address);    contentValues.put(COL_4,phone_number);    contentValues.put(COL_5,password);    long result = db.insert(TABLE_NAME, null , contentValues);    if (result == -1) {        return false;    }    else {        return true;    }}
查看完整描述

2 回答

?
尚方寶劍之說

TA貢獻(xiàn)1788條經(jīng)驗(yàn) 獲得超4個(gè)贊

Add this function to your DatabaseHelper.java


public boolean userExistance(String emailOrPhone, String pwd){


        String sql = "select * from " + TABLE_NAME + " where ("+ COL_3 +" = " + emailOrPhone +" OR "+ COL_4 +" = "+ emailOrPhone+ ") AND " + COL_5 + " = " + pwd;

        SQLiteDatabase mydb = this.getWritableDatabase();

        Cursor cursor = mydb.rawQuery(sql, null);

        if(cursor.getCount() > 0)

            return true;

        else

            return false;


    }


Then add call this function from your LoginActivity.java


DatabaseHelper mydb;

mydb = new DatabaseHelper(LoginActivity.this);

boolean exists = mydb.userExistance();

if(exists)

{

    Intent intent = new Intent(Login.this, Parent_Home.class);

    Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();

    startActivity(intent);

    finish();

}


查看完整回答
反對 回復(fù) 2022-07-27
?
翻過高山走不出你

TA貢獻(xiàn)1875條經(jīng)驗(yàn) 獲得超3個(gè)贊

在您的課程中添加以下方法DatabaseHelper。


public ArrayList<ParentModel> getParentData(String emailOrPhone,String pwd){

ArrayList<ParentModel> list = new ArrayList<>();

String sql = "SELECT * FROM " + TABLE_NAME+" WHERE ("+COL_3+"= "+emailOrPhone+" OR "+COL_4 +" = "+emailOrPhone+") AND "+COL_5 +" = "+pwd;

SQLiteDatabase mydb = this.getWritableDatabase();

Cursor cursor = mydb.rawQuery(sql, null);

if (cursor.moveToFirst()) {

    do {

        ParentModel parentModel = new ParentModel();

        parentModel.setID(cursor.getString(0));

        parentModel.setName(cursor.getString(1));

        parentModel.setSurname(cursor.getString(2));

        parentModel.setEmail(cursor.getString(3));

        parentModel.setPhone_number(cursor.getString(4));

        parentModel.setPassword(cursor.getString(5));

        list.add(parentModel);

    }

    while (cursor.moveToNext());

}

   return list;

}

并使用如下代碼:


if (mydb.getParentData(editTextEmailPhone.getText().toString(),editTextPassword.getText().toString()).size()>0) 

{

progressDialog.dismiss();

SharedPrefs.saveSharedSetting(this, "CaptainCode", "false");

Intent intent = new Intent(Login.this, Parent_Home.class);

Toast.makeText(this, "Success", Toast.LENGTH_SHORT).show();

startActivity(intent);

finish();

}

不要忘記初始化DatabaseHelper mydb。


查看完整回答
反對 回復(fù) 2022-07-27
  • 2 回答
  • 0 關(guān)注
  • 111 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)