"Android 9" ORM, Orm Method rewrite additions and deletions to change the operation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.