我怎么能检索的SQLite在android的特定coloumn?

问题描述:

我在ANDROID是新蜂所以我从SQLite的检索数据特别是特定列越来越问题,谁能帮助我知道它是如何可能。

I am new bee in ANDROID so am getting problem in retrieving data especially a particular column from SQLite ,can anyone HELP me to know how it is possible.

从检索SQLite数据库在Android的数据使用游标完成。 Android的SQLite的查询方法返回一个包含查询结果的Cursor对象。使用游标android.database.Cursor必须导入。

Retrieving data from SQLite databases in Android is done using Cursors. The Android SQLite query method returns a Cursor object containing the results of the query. To use Cursors android.database.Cursor must be imported.

为了让所有的列值

试试这个

DatabaseHelper mDbHelper = new DatabaseHelper(getApplicationContext());

SQLiteDatabase mDb = mDbHelper.getWritableDatabase();

Cursor cursor = mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_NAME,
            KEY_DESIGNATION}, null, null, null, null, null);

为了得到一个特定的列数据

试试这个,

Cursor mCursor = mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
              KEY_NAME, KEY_DESIGNATION}, KEY_ROWID + "=" + yourPrimaryKey, null,
              null, null, null, null);
        if (mCursor != null) {
          mCursor.moveToFirst();
        }

让光标之后,你可以遍历像

After getting the Cursor, you can just iterate for the values like

cur.moveToFirst(); // move your cursor to first row
// Loop through the cursor
        while (cur.isAfterLast() == false) {
             cur.getString(colIndex); // will fetch you the data
            cur.moveToNext();
        }

    cur.close();

希望这能解决你的问题。

Hope this solves your problem.