Harsha M V
Harsha M V

Reputation: 54949

Check to see if a value exists in DB

I am trying to do a check if the User-name entered by the user exists in the DB.

public Cursor checkUsername(String username) throws SQLException {
    Cursor mCursor = db.query(true, TABLE_USERS, new String[] { ID,
            KEY_NAME, KEY_USERNAME}, KEY_USERNAME + "="
            + username, null, null, null, null, null);
    if (mCursor != null) {
        return true;
    }
    return false;
}

When i return true or false i am getting an Error saying

Type mismatch: cannot convert from boolean to Cursor

i just want to return true or false from the DBAdaptor back to the Activity.

Upvotes: 1

Views: 2343

Answers (2)

John J Smith
John J Smith

Reputation: 11923

Try reformatting your sql query and provide the 'where' clause as one of the parameters in the database call :

public Cursor getRoute(long rowIndex)
{
    String where = KEY_ID + "=" + rowIndex;
    return db.query(TBL_ROUTES, null, where, null, null, null, null);       
}

Also, remember to close your cursor when you are finished with it, otherwise you will get other exceptions.

Upvotes: 0

Falmarri
Falmarri

Reputation: 48577

Your function returns a Cursor

public Cursor checkUsername()

Either change it to return a boolean, or return a cursor.

Upvotes: 4

Related Questions