: http://www.sqlite.org/download.html
Tutorial Address: http://www.runoob.com/sqlite/sqlite-tutorial.html
1. Install SQLite in Windows to test.
Reference Blog: How to install SQLite on Windows
Copy Sqlite3.def, Sqlite3.dll, and Sqlite3.exe to D:\sqlite
To create a database on the cmd command line, method:
Reference blog: SQLite3 How to create a database
SQLite statement tests, such as:
SQLite Paging Query method
Reference Blog: Three ways to query Android SQLite pages
Order by vs. limit considerations
Reference blog:
The odd question of using both order by and limit sometimes to return an incorrect result set
Http://bbs.chinaunix.net/thread-1276235-1-1.html
(Source: http://bbs.chinaunix.net/)
2. Android Use API
Reference Blog: A detailed description of SQLite application in Android
Note: You must add an SD card to create and delete file permissions
<!--Create and delete file permissions in SDcard - <uses-permissionAndroid:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/> <!--Write data permissions to an SD card - <uses-permissionAndroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permissionAndroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permissionAndroid:name= "Android.permission.CLEAR_APP_CACHE" /> <uses-permissionAndroid:name= "Android.permission.READ_PHONE_STATE" />
Initialize the database table code:
/*** Initialize database tables*/ Private voidinittable () {db= Openorcreatedatabase ("Db.db", Context.mode_private,NULL); Cursor Cursor= Db.rawquery (Sqlstatement.getinitstr (),NULL); Booleanresult =false; if(Cursor.movetonext ()) {intCount = Cursor.getint (0); if(count>0) {result=true; }} cursor.close (); if(!result) {//if error, create TABLEDb.execsql (Sqlstatement.getcreatestr ()); } }
Java string Formatting
Reference blog: The use of Java string Formatting-string.format ()
the string in String.xml cannot contain '
SQLite query data method, as follows:
String limit = string.valueof ( This. mpagesize); String SQL=sqlstatement.getsearchstr (Goods,limit,offset); Cursor Cursor= Db.rawquery (SQL,NULL); This. mdatalist =NewArraylist<dataitem> ();//Initialize list while(Cursor.movetonext ()) {intid = cursor.getint (cursor.getcolumnindex ("id"))); String ItemName= Cursor.getstring (Cursor.getcolumnindex ("Goods")); String Price= Cursor.getstring (Cursor.getcolumnindex ("Price")); DataItem Item=NewDataItem (Id,itemname, Price); This. Mdatalist.add (item); } cursor.close ();
Android--sqlite applications