Using the system to provide API data access interface operations database in Android

Source: Internet
Author: User

Increase in data
1. Create a Help class for SQLite data
Sqlitedatabase db = Helper.getwritabledatabase ();
2. Create a class contentvalues like the map collection to store key-value pairs
Contentvalues values = new Contentvalues ();
3, the need to increase the data to be stored in
Values.put ("name", name);
Values.put ("number", number);
4, the implementation of system-provided API data to increase the interface
Long id = db.insert ("person", null, values);
5. Close the database
Db.close ();
6. Returns the location of the added entry in the database
return ID;


Deletion of data
1. Create a Help class for SQLite data
Sqlitedatabase db = Helper.getwritabledatabase ();
2, the implementation of system-provided API data removal interface
int id = db.delete ("Person", "Name=?", new string[] {name});
3. Close the database
Db.close ();
4. Returns the location of the added entry in the database
return ID;

Deletion of data
1. Create a Help class for SQLite data
Sqlitedatabase db = Helper.getwritabledatabase ();
2. Create a class contentvalues like the map collection to store key-value pairs
Contentvalues values = new Contentvalues ();
3, the need to increase the data to be stored in
Values.put ("number", Newnumber);
4, the implementation of system-provided API data removal interface
int id = db.update ("Person", values, "Name=?", new string[] {name});
5. Close the database
Db.close ();
6. Returns the location of the deleted entry in the database
return ID;


Query for Data
1. Create a Help class for SQLite data
Sqlitedatabase db = Helper.getreadabledatabase ();
2, the implementation of the system provides API data query interface
cursor cursor = db.query ("person", NULL, "Name=?", new string[] {name}, NULL, NULL, NULL);
3. Querying all data in the database
4. Close the wiper project
Cursor.close ();
5. Close the database
Db.close ();
6. Returns whether there are any results in the database that need to be queried
return result;

Using the system to provide API data access interface operations database in Android

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.