Android Development Note "Sqlite Cursor use"

Source: Internet
Author: User
Tags sqlite database

Children's shoes using SQLite database should be no stranger to cursor, if you are engaged in. NET development you can interpret the cursor as a collection of data in ADO, which is equivalent to DataReader. Today, I'm going to take it out alone to deepen my understanding of using Cursor in Android.

About Cursor

When you understand and use the Android cursor, you must first know a few things about the cursor:


The Cursor is a collection of each row.
Use Movetofirst () to locate the first row.

Use MoveToNext () to navigate to the next line, returning a Boolean type
You must know the name of each column.
You must know the data type of each column.
The Cursor is a random data source.
All data is obtained by subscript.

Example:

The query () method actually splits the SELECT statement into several components and then acts as an input parameter to the method:

Sqlitedatabase db =databasehelper.getwritabledatabase (); Cursor Cursor= Db.query ("Person",Newstring[]{"Personid,name,age"}, "name like?",Newstring[]{% "%"},NULL,NULL, "PersonID desc", "a"); String columnnmaes[]=Cursor.getcolumnnames ();  String ColumnName;  String name; intPersonID; intAge ;  while(Cursor.movetonext ()) { for(inti = 0; i < columnnmaes.length; i++) {ColumnName=Columnnmaes[i];        if(columnname=="No.") PersonID=Cursor.getint (i); if(columnname=="name") name=Cursor.getint (i); if(columnname=="Age")=Cursor.getint (i);   }} cursor.close (); Db.close (); 


  

Android Development Note "Sqlite Cursor use"

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.