lundi 25 avril 2016

i want to fetch records from sqlite database and on login buttons click i want to check that record is there or not

i am performing login operation simple that on login button's click event it will find record frm sqlite database and if record is there then it will print message thet login successful. i did something like this

DbHelper db=new DbHelper(MainActivity.this);
            ArrayList<String> str=new ArrayList<String>();
            ArrayList<Student> arrayList=db.getdata();

            for(Student s:arrayList)
            {
                str.add(s.getUname()+"  "+s.getPass());
                if(uname.equals(s.getUname()) && pass.equals(s.getPass()))
                {
                    Toast.makeText(MainActivity.this,"Login Successful", Toast.LENGTH_LONG).show();

                }
                else
                {
                    Toast.makeText(MainActivity.this,"Invalid Username And Password", Toast.LENGTH_LONG).show();
                }
            }

in my DbHelper class

public ArrayList<Student> getdata()
{
    SQLiteDatabase db=getReadableDatabase();
    ArrayList<Student> arrayList=new ArrayList<Student>();
    String qry="select * from student";
    Cursor c=db.rawQuery(qry, null);
    while(c.moveToNext())
    {
        Student s=new Student(c.getInt(0),c.getString(1),c.getString(2));
        arrayList.add(s);
    }
    return arrayList;
}

Aucun commentaire:

Enregistrer un commentaire