String [] selectionArgs, String groupBy, String having, String orderBy) {
ArrayList
db = dbHelper.getReadableDatabase ();
Cursor cursor = db.query (table, columns, selection,
selectionArgs, groupBy, having, orderBy);
while (cursor.moveToNext () == true) {
Info info = new Info ();
info.id = Integer.valueOf (cursor.getString (cursor.getColumnIndex ("id")));
info.accountname = cursor.getString (cursor.getColumnIndex ("accountname"));
info.in_out = cursor.getString (cursor.getColumnIndex ("in_out"));
info.logo = Integer.valueOf (cursor.getString (cursor.getColumnIndex ("logo")));
info.moneys = cursor.getString (cursor.getColumnIndex ("moneys"));
info.remark = cursor.getString (cursor.getColumnIndex ("remark"));
info.sort = cursor.getString (cursor.getColumnIndex ("sort"));
info.time = cursor.getString (cursor.getColumnIndex ("time"));
info.user = cursor.getString (cursor.getColumnIndex ("user"));
infoList.add (info);
}
cursor.close ();
return infoList;
}
This is my query, three times on each check will play a bunch of error log information, the application can continue to query, no impact, but looking at those old error is uncomfortable, if every query finished are closed database, the efficiency will reduce a lot? There are other ways to solve it
------ Solution ---------------------------------- ----------
frequent switching must imaging applications performance, but none of the words may be an error. The continuous operation of the database can be put together, and then close
------ Solution ---------------------------- ----------------
must be closed. In the emulator will not be affected, in the real machine will crash
------ Solution ------------------------- -------------------
certainly have to shut Caesar, this is programming habits, otherwise there may be an overflow of
------ Solution - -------------------------------------------
landlord, do not hesitate to , and certainly the relationship, not just android is the case, the other the same way;
certainly have to do with the exception
------ For reference only --------------------------- ------------
Just put your cursor into all query is completed, that is, while complete closure can not it do? Why do you want to check off once again, as long as the end of all queries can be closed.
------ For reference only -------------------------------------- -
too frequent switching databases, will inevitably affect the performance of applications
------ For reference only ----------------------- ----------------
cursor used must be closed. Database is not how noticed
------ For reference only --------------------------------- ------
Cursor must be promptly closed after use, otherwise there will be long-time operation performance problems.
------ For reference only -------------------------------------- -
I did not get to know what you want to close a cursor object or a database connection
----- - For reference only ---------------------------------------
efforts to earn points, The landlord asked unclear.
------ For reference only ---------------------------------- -----
I said clearly points · ·
query the database I have used the above code, the cursor after the end of the while loop has cursor.close ();
My idea was to end the home side, it is the software and then close the database when the exit, just close the cursor at the end of the query, the situation now is that every inquiry will be out after a few error:
11-24 04:11:06.183: ERROR / Database (643): java.lang.IllegalStateException: / data / data / com.finance / databases / myRegister SQLiteDatabase created and never closed
how to resolve this situation, you need to close the database frequently do
------ For reference only ---------------------- -----------------
alas it off try · · ·
------ For reference only ---------------------------------------
landlord or you put the close operation function in the life cycle, I have worked in broadcasting registration have similar problems, like on onDestroied Lane.
------ For reference only -------------- -------------------------
onDestroied inside closed Cursor, database not related, do not know will not be affected
没有评论:
发表评论