[英]How to get values from database[Cursor Adapter] and store it to an array in java?
I would like to get the values from database of a particular column by executing a query. 我想通过执行查询从特定列的数据库中获取值。 Is it possible to do it after we do it to the Cursor Adapter or can we attain the values well before itself.
在我们对光标适配器执行此操作后是否可以执行此操作,或者我们可以在它们之前很好地获得这些值。 Kindly help on this with a snippet or a guide.
请使用片段或指南为此提供帮助。
Context context = getApplicationContext();
final DataBaseHelper db = new DataBaseHelper(context);
...
...
db.createDataBase();
..
...try catch logic etc
....
final Cursor c = db.getAllRows();
....
c.getString(4) // String value of 5th Column in Database
Cursor Adapter to Array 光标适配器到数组
ArrayList<String> mArrayList = new ArrayList<String>();
c.moveToFirst();
while(!c.isAfterLast()) {
mArrayList.add(c.getString(c.getColumnIndex(DataBaseHelper.KEY_NAME));
c.moveToNext();
}
DataBaseHelper class has following DataBaseHelper类有以下内容
public Cursor getAllRows()
{
return myDataBase.query(DATABASE_TABLE, new String[] {
KEY_ROWID,
KEY_NAME,
KEY_YEAR,
KEY_QUOTE,
KEY_REF},
null,
null,
null,
null,
null);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.