Use Database
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.
For 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 ){
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.
Database debugging
The android SDK 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.
Use Network Connection
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.