SQLite Basic Operation

Source: Internet
Author: User
Tags sqlite sqlite db

1. Create a database and open

SQLite db = Openorcreatedatabase ("user.db", mode_private,null);

2. Create a table

Db.execsql ("CREATE TABLE book (_id integer primary key autoincrement,author text,price real,pages integer, Name text)");

3. Inserting data

Sqlitedatabase db = Dbhelper.getwritabledatabase ();
Contentvalues values = new Contentvalues ();
Values.put ("name", "the Da Vinci Code");
Values.put ("Author", "Dan Brown");
Values.put ("pages", 454);
Values.put ("Price", 16.96);
Db.insert ("book", null, values);
Values.clear ();//can store more than one data after emptying

4. Updating data

Values.put ("Author", "Kobe")
Db.update ("book", Values, "_ID>?", New string[]{"3"});

5. Delete data

Db.delete ("book", "PAGES>?", New string[]{"500"});

6. Querying data

Db.rawquery ("SELECT * from book", NULL);

  

Data type (null: null, Integer: integer value, REAL: Floating-point value, TEXT: String, BLOB: binary)

SQLite Basic Operation

Related Article

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.