SQLite (1, Basic)

Source: Internet
Author: User
Tags sqlite

SQLite is a lightweight embedded database, sqlite consumption of resources is very low, in the embedded device may be as long as hundreds of K of memory. Faster than MySQL or Postgre.

Note that SQLite does not belong to the client-server model database, its engine will be connected to the program as a part of it, so there is no db such as MySQL, need to be a communication protocol and database instance interaction.

It is API execution for SQLite. and the entire database, including definitions, tables, indexes, and data are stored in a single file.

in this design, SQLite, which supports transactions, locks the entire data file when it executes a transaction. Here is a basic example of a program:

db = Openorcreatedatabase (db_name, This. Mode_private,NULL); Db.execsql ("DROP TABLE IF EXISTS users"); Db.execsql ("CREATE TABLE IF not EXISTS users (_id INTEGER PRIMARY KEY autoincrement, username varchar, password varchar)"); Db.execsql ("INSERT into Users VALUES (NULL, ' Fredric ', ' Fredricpassword ')"); Contentvalues CV=Newcontentvalues (); Cv.put ("username", "Sinny"); Cv.put ("Password", "Sinnypassword"); Db.insert ("Users",NULL, CV); Cursor Cursor= Db.rawquery ("SELECT * from users",NULL);  while(Cursor.movetonext ()) {log.i (tag_activity, cursor.getstring (Cursor.getcolumnindex ("Username"))); LOG.I (Tag_activity, Cursor.getstring (Cursor.getcolumnindex ("Password"))); } cursor.close ();

Print output: Fredric, Fredricpassword, Sinny, Sinnypassword

SQLite (1, Basic)

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.