I. Overview of SQLite
SQLite is a lightweight, embedded, relational database. It supports SQL language, open source, and portability is good. Its data is stored as a single file, stored in the data/data/< project folder >/database.
Ii. General description of the class
Sqliteopenhelper Abstract class: Provides database creation, opening, closing, etc. by implementing a user class from this class of inheritance. Sqlitedatabase Database Access classes: Perform operations such as inserting records into the database, querying records, and so on. CURSOR Query structure Operation class: Used to access records in query results 2.1 sqliteopenhelper using Sqliteopenhelper (context context, String name, Sqlitedatabase.cursorfactory Factory, int version): Constructs a method for instantiating an object OnCreate (Sqlitedatabase db): A method that executes when a database is created Onupgrade ( Sqlitedatabase db, int oldversion, int newversion): method to be executed when updating the database 2.2 Sqlitedatabase update class operation with native SQL void Execsql (String sql) ; Executes the sqlvoid execsql (String sql,object[] bindargs) with no arguments, and executes SQL with parameters
// DBHelper is a custom class that inherits the Sqliteopenhelper New DBHelper (This, "ccshxt.db",null, 1); = dbhelper.getwritabledatabase (); Db.execsql ("Delete from student"); Db.execsql ("INSERT into student (Name,age) VALUES (?,?)",new object[]{"Zhang San", "a"); Db.close ();
Native SQL for query class operations
Cursor rawquery (String sql,string[] selectionargs) Executes the SELECT statement with parameters;
String sql = "SELECT * FROM student WHERE _id >?" ; = Db.rawquery (sql,new string[]{"4"}); while (Cursor.movetonext ()) { "name:" +cursor.getstring (Cursor.getcolumnindex ("name")); }
Use of SQLite (i): Introduction and native SQL Operations database