Create a class that inherits Sqliteopenhelper, overrides his constructor method, OnCreate (), Onupgrade ()
After building the Sqliteopenhelper instance, call his Getreadabledatabase () Getwritabledatabase () method to create the database
Getreadabledatabase () and Getwritabledatabase () Two methods can create or open an existing database
The difference is that when the database is not writable, the object returned by the Getreadabledatabase () method will open the database in a read-only manner, and the Getwritabledatabase () method will show an exception
Placed in the/data/data/<package name>/databases/directory
Public classFeedreaderdbhelperextendsSqliteopenhelper {//If You change the database schema, you must increment the database version. Public Static Final intDatabase_version = 1; Public Static FinalString database_name = "Feedreader.db"; PublicFeedreaderdbhelper (Context context) {Super(Context, database_name,NULL, database_version); } Public voidonCreate (Sqlitedatabase db) {db.execsql (sql_create_entries); } Public voidOnupgrade (Sqlitedatabase db,intOldversion,intnewversion) { //This database was only a cache for online data and so it upgrade policy is//To simply to discard the data and start overDb.execsql (sql_delete_entries); OnCreate (DB); } Public voidOndowngrade (Sqlitedatabase db,intOldversion,intnewversion) {Onupgrade (db, Oldversion, newversion); }}
Use Contentvalues objects to update data, insert data
The cursor object is used to query
Android uses SQLite to store data