Android-sqlite Database < five >

Source: Internet
Author: User

1.sqlite

It's a database that Android uses to manage data, lightweight and efficient.

View and manage SQLite databases in Android

Http://www.cnblogs.com/walkingp/archive/2011/03/28/1997437.html

2.SQLiteOpenHelper class ( abstract class )

It is used to create, open the database. That is, to manage the SQLite database, note: It is an abstract class that requires an inheritance implementation

Construction method: Factory is generally null, it can create/open/Manage Database

Sqliteopenhelper (context context, String name, sqlitedatabase.cursorfactory Factory, int version)

Member Methods:

Sqlitedatabase getreadabledatabase ();//create and/or open a database and can only read

         sqlitedatabase  getwritabledatabase ()//create and/or open a database and can read or write operations.

         oncreate (Sqlitedatabase db) ;//Called when The database is created for the first time.

Onupgrade (sqlitedatabase db, int oldversion, int newversion);//called when the database needs Graded.

3.SQLiteDatabase class

Database classes, which are used to manage databases, can use SQL statements.

it needs to be created using the Sqliteopenhelper getreadabledatabase () method or the getwritabledatabase () method, as long as both methods are created.

Member Methods:

execsql (String sql) ;//eg:db.execsql ("CREATE table user (ID int,name varchar (20))")

Insert (String table, string nullcolumnhack, contentvalues values);//Insert Method

< Span class= "Apple-converted-space" >               update (string< Span class= "Apple-converted-space" > table, contentvalues values, string whereclause, string[] whereargs)

< Span class= "Apple-converted-space" >< Span class= "Sympad" >               //eg:  db.update ("User", Values, "id=", New string[]{"1"});
                          The first parameter is the name of the table to be updated, the second argument is a Contentvaleus object, The third parameter is the WHERE clause

Delete (string table, string whereclause, string[] Whereargs);//Delete method

Query operation:

    classQuerylistenerImplementsonclicklistener{@Override Public voidOnClick (View v) {System.out.println ("AAA------------------"); LOG.D ("Mydebug", "myfirstdebugmsg"); Databasehelper DBHelper=NewDatabasehelper (sqliteactivity. This, "test_mars_db"); Sqlitedatabase DB=dbhelper.getreadabledatabase (); Cursor Cursor= Db.query ("User",Newstring[]{"id", "name"}, "Id=?",Newstring[]{"1"},NULL,NULL,NULL);  while(Cursor.movetonext ()) {String name= Cursor.getstring (Cursor.getcolumnindex ("name")); System.out.println ("Query--->" +name); }        }    }

Android-sqlite Database < five >

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.