Android data storage-available storage solutions

Source: Internet
Author: User
Tags sqlite query

Android provides full support for SQLite databases. Any database you create in the application, and any class in the application can be accessed by name. We recommend that you create an SQLite database by creating a subclass of the SQLiteOpenHelper class and override the onCreate () method. In this method, you can run the SQLite command to create tables in the database. Example: public class DictionaryOpenHelper extends SQLiteOpenHelper {private static final int DATABASE_VERSION = 2; private static final String DICTIONARY_TABLE_NAME = "dictionary "; private static final String DICTIONARY_TABLE_CREATE = "create table" + DICTIONARY_TABLE_NAME + "(" + KEY_WORD + "TEXT," + KEY_DEFINITION + "TEXT);"; DictionaryOpenHelper (Context context) {super (context, DATABASE_NAME, Null, DATABASE_VERSION) ;}@ Override public void onCreate (SQLiteDatabase db) {db.exe cSQL (DICTIONARY_TABLE_CREATE );}} you can use the constructor defined in the SQLiteOpenHelper class implementation to obtain an instance. To read and write data from a database, call the getWritableDatabase () and getReadableDatabase () methods respectively. Both methods return a SQLiteDatabase object representing the database and provide the SQLite operation method. You can use SQLiteDatabase. the query () method is used to execute SQLite queries. This method receives various query parameters, such as the tables to be queried, query conditions, selected columns, groups, and mappings among others. For complex queries, such as columns with aliases, you should use the SQLiteQueryBuilder class, which provides several convenient query methods. Each SQLite query returns a Cursor object pointing to all queried rows. You can use this cursor mechanism to view the database query results. The Android SDK for database debugging contains the sqlite3 database tool, which allows you to browse table content, run SQL commands, and execute useful functions on other SQLite databases. See Examining sqlite3 databases from a remote shell to learn how to use this tool. You can use the network (when it is available) to save and restore Web service-based data. Use the classes in the following package to perform network operations. 1. java.net. * 2. android.net. * tip: Android does not impose any restrictions on the standard SQLite concept. We recommend that you include an auto-increment primary key field. You can use this unique ID to quickly find records. This is not mandatory for private data, but if you want to implement a content provider, you must include the unique ID used by a BaseColumns. _ ID constant.

Related Article

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.