Reputation: 3
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
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
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
Reputation: 270
Try below code
here help is object of helper class
help.KEY_EMAIL+"="+ "'"+cnt+"'"
Upvotes: 0
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