SQLite is a lightweight database. It is used on android. A database file represents a database. The SQL syntax is basically the same as that of mysql. The expressions are different.
Obtain the SQLiteDatabase object
SQLiteDatabase Method
Static SQLiteDatabaseOpenDatabase (String path, SQLiteDatabase. CursorFactory factory, int flags)
E: SQLiteDatabase db = SQLiteDatabase. openDatabase (path, factory, flags); // open the path file represented by path
Static SQLiteDatabaseOpenOrCreateDatabase (File file, SQLiteDatabase. CursorFactory factory)
E: SQLiteDatabase db = SQLiteDatabase. openOrCreateDatabase (mFile, factory); // open the database file corresponding to the mFile. If the file does not exist, create
Static SQLiteDatabaseOpenOrCreateDatabase (String path, SQLiteDatabase. CursorFactory factory );
E: SQLiteDatabase db = SQLiteDatabase. openOrCreateDatabaes (mPath, factory); // open the database file corresponding to mPath. If the file does not exist, create
========================================================== ========================================================== ======================================
SQLiteDatabase provides several methods to operate databases
ExecSQL (String SQL, Object [] objs); // Execute SQL statements with placeholders
ExexSQL (String SQL );// Directly execute the SQL statement
Insert (String table_name, String nullColumn, ContentValues values); // execute the SQL insert statement
Delete (String table_name, String where, String [] whereArgs); // delete
Update (String table_name, ContentValues values, String where, String [] whereArgs); // update
For example:
Db.exe cSQL ("select * from table_name where id>? ", New int [] {10 });//? It indicates a placeholder. The placeholder must be of the same type and sequence as the following array.
Db.exe cSQL ("select * from table_name where id> 10") // similar to the first sentence, execute select * from table_name where id> 10 in a mysql statement;
It seems that only execSQL (xc) is used. This statement basically solves all the needs... add, delete, modify, and query...
ContentValues values = new ContentValues ();
Values. put ("name", "admin ");
Values. put ("age", "20"); // values. put (columnName, value) ;=> Map. put (key, value );
Db. insert (table_name, null, values); // insert records in the table_name Table, column name = value admin age = 20
// Equivalent to insert into table_name (name, age) values ("admin", 20 );
Db. delete ("table_name", "name like", new String [] {"a % "}); // delete a row whose name column value starts with a record ==> delete table_name where name like "a % ";
Values. put ("age", "25 ");
Db. update ("table_name", values, "age =", new String [] ("20"); // update the record whose age is 20, the modified value is placed in values ==> update table_name set age = 25 where age = 20;