Summary of some key points of android app using SQLite database

/Data / data / package name / databases is the directory where the program stores data, and data is the path returned by the environment. Getdatadirectory () method. After finding the database, you can select user.db to perform the export. Debug with the real machine. If the data directory cannot be opened, it means that your mobile phone does not have root. It is OK to use the simulator instead.

1. Get sqlitedatabase object:

2. Sqlitedatabase provides the following methods:

3. Execute query and rawquery operations to return a cursor object, which can traverse the contents of the whole query. Cursor provides the following methods to move the cursor:

The following is an example of creating an sqlitedatabase object and querying only with SQL statements

4. Add, delete, query and modify relevant parameters:

Table: table name of query data columns: column name to be queried whereclause: query condition clause, placeholder "?" whereargs: used to pass in parameter value for placeholder groupby: used to control grouping; having: used to filter grouping; orderby: used to sort records

Contentvalues is a wrapper for key / value. It can be used to encapsulate the data to be inserted or modified in the form of key / value, which can be used directly when using the corresponding addition and modification methods. It has two ways to deposit and withdraw:

The following example uses the built-in function to add, delete, modify and query the database:

5. Sqliteopenhelper: sqliteopenhelper is a help class that manages our database by inheriting it and implementing oncreate method and upgrade method.

In the following example, create a new class to inherit sqliteopenhelper

Then you can create the object of this subclass in the main activity, and get the sqlitedatabase object through the get method of this class

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>