从数据库获取联系时出错

时间:2014-02-05 08:16:31

标签: java android database eclipse relational-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;
        }

正如您在我的代码中所看到的,我正在尝试从我的数据库访问联系人。但是在运作方面存在一些问题。 声明

“KEY_EMAIL +”=“+ e_mail”

是我猜的主要问题...... **

Plz .. help !!!!

4 个答案:

答案 0 :(得分:1)

尝试这种方式:

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

答案 1 :(得分:0)

尝试以下代码

        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();

答案 2 :(得分:0)

尝试以下代码

这里的帮助是辅助类的对象

help.KEY_EMAIL +“=”+“'”+ cnt +“'”

答案 3 :(得分:0)

使用此代码,我检查了它。

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();
                }
            }