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

时间:2015-04-26 14:17:34

标签: android sqlite where

我想获得一个带有id的行的单列,我应该

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

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

我得到一个光标吗?

2 个答案:

答案 0 :(得分:1)

你可以使用query()方法

<?xml version="1.0" encoding="utf-8"?>
    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="LaLaLa">


    </TextView>

或者你可以执行行查询,就像你提出的一些错误被删除

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

答案 1 :(得分:0)

*表示表中的所有列,如果您只需要指定的名称。 一旦你创建了字符串,就可以使用rawQuery()函数。