Android--sqlite applications

Source: Internet
Author: User

: 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.