Orm
ORM is the abbreviation of object/relational mapping, which is translated into object-relational mapping. The advantage of storing fields in the form of key-value pairs is that the data can be added and modified without an SQL statement.
The Sqlitdatabase class encapsulates the insert (), delete (), and Update () methods, which are three ways to perform additions and deletions to the database without the need for an SQL statement.
Java is an object-oriented language, and most of the popular databases are relational databases. ORM makes object-oriented programming easy to work with data in relational databases.
Operation Steps :
Step 1, create the Contentvalues object.
Step 2, call the object in the Get (), put () and other methods, in the form of key-value pairs to access data.
Step 3, call the Sqlitdatabase class of the Insert (), delete (), update () method to make the pruning operation.
Orm method rewriting additions and deletions to change operations
Use the Insert (), delete (), and Upate () methods in the database class instead of the Execsql method to complete the pruning operation.
/**inserting data into the database*/ Public voidInsert () {Sqlitedatabase db= This. Getwritabledatabase (); //the object can manipulate key-value pairs of dataContentvalues values=Newcontentvalues (); Values.put ("Name", "Liu Bei");//Storing Data//table name, forcing NULL to insert a column name that is worth the data column, record the dataDb.insert ("Person",NULL, values);}/**Delete data from a database*/ Public voidDelete (String [] args) {Sqlitedatabase db= This. Getwritabledatabase (); Db.delete ("Person", "id=?", args); }/**updating data in a database*/ Public voidUpdate (String []args) {Sqlitedatabase db= This. Getwritabledatabase (); Contentvalues Values=Newcontentvalues (); Values.put ("Name", "Zhao Yun");//Storing DataDb.update ("person", values, "id=?"), args); } ORM Rewrite and delete and change operation
"Android 9" ORM, Orm Method rewrite additions and deletions to change the operation