Use of SQLite (i): Introduction and native SQL Operations database

Source: Internet
Author: User
Tags sqlite

I. Overview of SQLite

SQLite is a lightweight, embedded, relational database. It supports SQL language, open source, and portability is good. Its data is stored as a single file, stored in the data/data/< project folder >/database.

Ii. General description of the class

Sqliteopenhelper Abstract class: Provides database creation, opening, closing, etc. by implementing a user class from this class of inheritance. Sqlitedatabase Database Access classes: Perform operations such as inserting records into the database, querying records, and so on. CURSOR Query structure Operation class: Used to access records in query results 2.1 sqliteopenhelper using Sqliteopenhelper (context context, String name, Sqlitedatabase.cursorfactory Factory, int version): Constructs a method for instantiating an object OnCreate (Sqlitedatabase db): A method that executes when a database is created Onupgrade ( Sqlitedatabase db, int oldversion, int newversion): method to be executed when updating the database 2.2 Sqlitedatabase update class operation with native SQL void Execsql (String sql)  ; Executes the sqlvoid execsql (String sql,object[] bindargs) with no arguments, and executes SQL with parameters
// DBHelper is a custom class that inherits the Sqliteopenhelper        New DBHelper (This, "ccshxt.db",null, 1);         = dbhelper.getwritabledatabase ();        Db.execsql ("Delete from student");        Db.execsql ("INSERT into student (Name,age) VALUES (?,?)",new object[]{"Zhang San", "a");        Db.close ();

Native SQL for query class operations

Cursor rawquery (String sql,string[] selectionargs) Executes the SELECT statement with parameters;

String sql = "SELECT * FROM student WHERE _id >?" ;         = Db.rawquery (sql,new string[]{"4"});          while (Cursor.movetonext ()) {            "name:" +cursor.getstring (Cursor.getcolumnindex ("name"));        }

Use of SQLite (i): Introduction and native SQL Operations database

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.