First step: Write a class, inherit Sqliteopenhelper
1 Public class extends Sqliteopenhelper {23 }
Step Two: Add a constructor and specify the necessary parameters
// name : database names // factory: cursor Factory // version: public mydatabaseopenhelper (context context) { Supernull, 1);}
And in the OnCreate method , the SQL statement is executed through the DB object to create the table
Db.execsql ("CREATE Table Users" (_id integer primary key autoincrement, name varchar (ten), password varchar (20)));
Step three: The new object, and then the DB instance object, you can create the database.
New Mydatabaseopenhelper (this); // This line of code executes before the database file is created Sqlitedatabase db = Helper.getreadabledatabase ();
Attention:
- The Oncreate method will only be executed when the database is first created
Generally here to create a table,
- The 0nupgrade method will only be executed if the database version is upgraded
The version of the database can only be upgraded, not degraded, the database version of the upgrade can be skip.
This is mostly used to modify the structure of existing tables. Or add a new table.
Use SQLite database to store data under Android