Android sqlite Where 子句返回带有 id 的一行列

Android sqlite Where clause returning one row column with id

我想获取带有 id 的行的单个列,我应该这样做

 String selQ = "SELECT " + name + " FROM " + table+ " WHERE " + id+ " = '" + id + "'";

 String selQ = "SELECT * FROM " + table + " WHERE " + id+ " = '" + id + "'";

我要拿个光标吗?

* 表示 table 中的所有列,如果您只想要您需要指定的名称。 制作字符串后,您可以使用 rawQuery() 函数。

你可以使用 query() 方法

private Cursor getSingleRow(int id){    
    Cursor cur = db.query(TABLE, null,
                 "_id= ?", new String[] { "" + id }, null,
                null, null);
        if (cur != null) {
            cur.moveToFirst();
        }
        return cur;
}

或者您可以像您建议的那样执行行查询并删除一些错误

db.rawQuery("SELECT * from " + TABLE_NAME
            + "WHERE _id="+id , null);