user3269876
user3269876

Reputation: 3

Error in getting a contact from database

public Cursor getContact(String e_mail) throws SQLException
        {
            String str[] = {KEY_EMAIL,KEY_PASSWORD};



            Cursor mCursor = db.query("Users_Detail", str, KEY_EMAIL + "=" + e_mail, null,
                    null, null, null, null);
                    if (mCursor != null) {
                        mCursor.moveToFirst();
                    }
                    return mCursor;
        }

As you can see in my code I'm trying to access contact from my database. But there is some problem in the functioning. The statement

"KEY_EMAIL + "=" + e_mail"

is the main problem i guess... **

Plz.. help!!!!

Upvotes: 0

Views: 51

Answers (4)

Mohammad Rababah
Mohammad Rababah

Reputation: 1726

use this code and I checked it.

Cursor cursor = null;
            try {
                cursor = getApplicationContext().getContentResolver().query(
                        Phone.CONTENT_URI, null, null, null,
                        Phone.DISPLAY_NAME + " ASC");
                int contactIdIdx = cursor.getColumnIndex(Phone._ID);
                int nameIdx = cursor.getColumnIndex(Phone.DISPLAY_NAME);
                int phoneNumberIdx = cursor.getColumnIndex(Phone.NUMBER);
                cursor.getColumnIndex(Phone.PHOTO_ID);
                cursor.moveToFirst();
                do {
                    cursor.getString(contactIdIdx);
                    String name = cursor.getString(nameIdx);
                    String phoneNumber = cursor.getString(phoneNumberIdx);
    } while (cursor.moveToNext());
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }

Upvotes: 0

M D
M D

Reputation: 47817

Try on this way:

Cursor mCursor = db.query(true, "Users_Details",
            str,
            "KEY_EMAIL" + "='" + email + "'", null, null, null, null,
            null);
    if (mCursor != null) {
        mCursor.moveToFirst();
    }

Upvotes: 1

Anil Kanani
Anil Kanani

Reputation: 270

Try below code

here help is object of helper class

help.KEY_EMAIL+"="+ "'"+cnt+"'"

Upvotes: 0

suresh
suresh

Reputation: 414

Try Below Code`

        String query = "SELECT * FROM Users_Detail WHERE KEY_EMAIL = '"
            + e_mail + "'";
    int data = 0;
    db1 = dbHelper.getReadableDatabase();
    Cursor cursor = db1.rawQuery(query, null);

    if (cursor.moveToFirst()) {

        //getDetails
    }
    cursor.close();
    db1.close();

Upvotes: 0

Related Questions