我使用的查询抽取数据库,什么是暂时存储数据的最佳实践。目前我使用ArrayList来提取数据,但我认为这可能不是最好的设计实践。如何保存从游标中提取数据库中的Android
感谢
Cursor cur5 = database2.rawQuery("select ID from Quote where EmoticonID=? and SubCategoryID=?" ,new String [] {Integer.toString(gcid), Integer.toString(scid)});
if(cur5.getCount()==0){
Log.i("TAG Screen3", "No Quotes ID found for Particular ID");
if (helper2 != null) {
helper2.close();
}
if (database2 != null) {
database2.close();
}
}else{
cur5.moveToFirst();
do {
quoteid.add(Integer.parseInt(cur5.getString(0)));
Log.i("TAG Screen3 Quote ID", (cur5.getString(0)));
} while (cur5.moveToNext());
if(cur5 != null){
cur5.close();
}
if (helper2 != null) {
helper2.close();
}
if (database2 != null) {
database2.close();
}
}
“抽取数据库”?你什么意思?你正在提取数据库中的所有**数据?你能显示查询吗? – m0skit0 2012-02-23 12:13:10
在少量数据的情况下,您可以使用SharredPreferences – Android 2012-02-23 12:13:19
作为一种观察,存在大量不必要的代码和重复数据。 'cur5.moveToFirst()'可以像'cur5.moveToFirst()'一样去'; if(cur5.getCount()');将它修剪成一个'while(cur5.moveToNext())'循环,你的代码大小约为一半 – 2012-02-23 12:42:29