SQLite supports storing NULL, INTEGER, REAL, TEXT, and BLOB data, but they will all be converted to the TEXT string type, so you can directly store any data you want as TEXT.
SQLite requires the primary key to be _id (although it can also be id, but it is not standardized), and the primary key can only use the INTEGER type.
Location of Database File
/data/data/com.xxx.app/database/xxDB.db
Customize a Class that Inherits the SQLiteOpenHelper Class
Using the singleton pattern
<name>DB.db: Name of the database file 1: Version number, starting from 1. When upgrading the database in the future, increase the version number by 1
// Database initialization, this method will only be executed once, usually used to execute the create table statement @Override publicvoidonCreate(SQLiteDatabase sqLiteDatabase) { // Create the table using SQL statement Stringsql="CREATE TABLE users(_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT)"; sqLiteDatabase.execSQL(sql); }
// Database upgrade @Override publicvoidonUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
} }
Create Database File
When creating the object for the first time, the database file will be created, and the data table will be created through the onCreate() method.
if (db.isOpen()) { // Return the cursor Cursorcursor= db.rawQuery("<select>", null);
// Iterate through the cursor while (cursor.moveToNext()) { // Get the value of the first column cursor.getInt(0);
// Get the value of the specified column name cursor.getInt(cursor.getColumnIndex("_id")); } // Close the cursor cursor.close(); // Close the database db.close(); }