Returns null 即使在 Android sqlite 中不为 null

Returns null even when not null in Android sqlite

当数据出现在 sqlite 中的位置时,我得到一个空值

Cursor c = db.query("SELECT * FROM table WHERE id " = '" + value + "'", null);

if(c !=null && c.moveToFirst())
{
     temp = c.getString(c.getColumnIndex(b1));

     Log.v(TAG, ""+temp);
}

日志文件是

------------
Tag   Text
-------------
class null 

------------- 

该值存在,但我得到的是空值,能否对其进行整理。

如果游标为空,它显然应该跳过 if 语句,但它会执行该语句。

对于其他一些值,我得到了答案

Tag    Text
-----------
class  100
----------
class  86

感谢您的时间和回复

你没有写正确的SQL查询
这是正确的查询

Cursor c = db.rawQuery("SELECT * FROM "+ table +" WHERE id  = " + value , null);

你也可以使用db.query()这样的方法

    Cursor cursor = db.query(TABLE_NAME, // a. table
            COLUMNS, // b. column names as array of strings

            KEY_ID + "= ?", // c. selections

            new String[] { String.valueOf(id) }, // d. selections args
            null, // e. group by
            null, // f. having
            null, // g. order by
            null); // h. limit

    // 3. if we got results get the first one
    if (cursor != null)
        cursor.moveToFirst();

    temp = cursor.getString(c.getColumnIndex(b1));