Recently, the SQLite database was used due to functional requirements. I found a lot of useful knowledge on the Internet. Although many articles are the same, everyone knows it here!
In the Data Reading function, no matter which version of the article, the while method is used to read the data. The Code is as follows:
/*** Query list * @ throws exception */Public void selectlist () throws exception {dbhelper = new dbhelper (this. getcontext (); dbhelper. open (); cursor returncursor = dbhelper. findlist ("user", new string [] {"ID", "username", "password"}, "username = 'test'", null, null, "id DESC"); While (returncursor. movetonext () {string id = returncursor. getstring (returncursor. getcolumnindexorthrow ("ID"); string username = returncursor. getstring (returncursor. getcolumnindexorthrow ("username"); string Password = returncursor. getstring (returncursor. getcolumnindexorthrow ("password "));}}
Maybe you have modified the above Code in your own application, but it is estimated that there are also a lot of obfuscation like me. The original copy is no longer available! Then the problem arises. I am working on resumable upload of Android files. Test results, there is always a file that cannot be passed to the server. The reason is that on this while, the while condition is whether the next row is read successfully. If yes, the cursor is located at the next data position, therefore, the first data cannot be read.
This problem is understandable. It is estimated that the problem has been corrected after debugging, but it turned out to be overwhelming on the Internet. After reading more than a dozen articles, none of them have been corrected. Although I agree with everyone's suggestions, this trend is not good after all.
Paste the modified Code:
/*** Query list * @ throws exception */Public void selectlist () throws exception {dbhelper = new dbhelper (this. getcontext (); dbhelper. open (); cursor returncursor = dbhelper. findlist ("user", new string [] {"ID", "username", "password"}, "username = 'test'", null, null, "id DESC"); If (returncursor. movetofirst () {do {string id = returncursor. getstring (returncursor. getcolumnindexorthrow ("ID"); string username = returncursor. getstring (returncursor. getcolumnindexorthrow ("username"); string Password = returncursor. getstring (returncursor. getcolumnindexorthrow ("password");} while (returncursor. movetonext ());}}
The above Code does not return values. It is only used for demonstration!
In fact, there is nothing to worry about when an error occurs during reposted articles, but we hope that you can modify your original blog in time after discovering the error to develop a good atmosphere. Take responsibility for your own blog and start from yourself!