Using SQL statements to manipulate databases in Android

Source: Internet
Author: User

Increase in data
1. Create a Help class for SQLite data
Sqlitedatabase db = Helper.getwritabledatabase ();
2, execute the SQL statement, to achieve the increase of data
Db.execsql ("INSERT into person (name,number) VALUES (?,?)", new object[] {name, number});
3. Close the database
Db.close ();

Deletion of data
1. Create a Help class for SQLite data
Sqlitedatabase db = Helper.getwritabledatabase ();
2, execute the SQL statement, to implement the data modification
Db.execsql ("Delete from person where name=?", new object[] {name});
3. Close the database
Db.close ();

Modification of data
1. Create a Help class for SQLite data
Sqlitedatabase db = Helper.getwritabledatabase ();
2, execute the SQL statement, to implement the data modification
Db.execsql ("Update person set number=?") Where Name=? ", new object[] {newnumber, name});
3. Close the database
Db.close ();

Query for Data
1. Create a Help class for SQLite data
Sqlitedatabase db = Helper.getreadabledatabase ();
2. Call the Rawquery method in the Help class of the SQLite database to query the data
cursor cursor = db.rawquery ("select * from person where name=?", new string[] {name});
3. Querying all data in the database
Boolean result = Cursor.movetonext ();
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 SQL statements to manipulate databases 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.