user1061793
user1061793

Reputation: 1077

How can I compare Entered Email from the sqlite database in android

I have creating a login form where I have created sqlite database,in this I want to compare Count or Email in database if my email is in database so it will check the password,or if my email is not in database so it will call the web service.

So how can I compare Email or check count which user enter from the database?

Upvotes: 2

Views: 3092

Answers (3)

S HemaNandhini
S HemaNandhini

Reputation: 333

You can enter the query like this

Cursor cm = odb.rawQuery("SELECT * FROM " +
        DATABASE_TABLE + " WHERE " +
        KEY_ID + "=? AND " +
        KEY_DATE + "=?",
        new String[]{id, date});

Upvotes: 0

Sayyaf
Sayyaf

Reputation: 326

use rawquery("SELECT * FROM YOUR_DATABASE_TABLENAME WHERE username=? AND password=?",new String[] {username,password}); store it in a cursor object as Cursor=db.rawquery("SELECT * FROM YOUR_DATABASE_TABLENAME WHERE username=? AND password=?",new String[] {username,password}); and check if the cursor is null or not, if not the check the (cursor.getcount()>0) to know whether error occurs or not, if it returns -1 error has occured. return to the mainActivity where the fuction is present and display the result in toast or someother way. hope it helps.

Upvotes: 0

Harsha M V
Harsha M V

Reputation: 54949

In this method i check if the username already exists in the database or not.

// Read Section
public Boolean checkUsername(String username) throws SQLException {
    Cursor mCursor = db.query(TABLE_USERS, new String[] { ID, KEY_NAME,
            KEY_USERNAME }, KEY_USERNAME + "=" + "'" + username + "'",
            null, null, null, null, null);

    if (mCursor.moveToFirst()) {
        return true;
    }
    return false;
}

In this method i pass in Username and Password to check if the credentials match and if they do i log them in.

public Cursor login(String username, String password) throws SQLException {
    Cursor mCursor = db.query(TABLE_USERS, new String[] { ID, KEY_NAME,
            KEY_USERNAME }, KEY_USERNAME + "=" + "'" + username + "'"
            + "AND " + KEY_PASSWORD + "=" + "'" + password + "'", null,
            null, null, null, null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }
    return mCursor;
}

Upvotes: 1

Related Questions