我怎么能检索的SQLite在android的特定coloumn? [英] How can I retrieve a particular coloumn from SQLite in android?
问题描述
我在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.
这篇关于我怎么能检索的SQLite在android的特定coloumn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!