Android SQLite Database Introduction

This article is an introduction to SQLite database classes and methods. It is a pre-sequal to the complete Android SQLite Example.

SQLite database in Android

Do you want to store and save data of your Android application in your device? The solution is very easy as Android has built in SQLite database engine with it. SQLite is SQL database, it stores data of your application in a text file. It is very light weight and also open source. SQLite database supports standard features of relational database. It supports text, integer and real data types. Android.database.sqlite package has all you need to save data of your application. SqliteDatabase class has many different methods to create database, to execute SQL commands and to delete database.

Methods of SQLiteDatabase class

Here are some public methods of SQLiteDatabase class.

  • createSQLIteDatabase( SQLiteDatabase.Cursorfactory factory): Used to create SQLite database.
  • complieStatement( String sql): It compiles SQL statements.
  • deleteDatabase( File file): It deletes whole database.
  • delete( String table, String wholeClass, String[] whereArgs): Method to delete rows in a database.
  • getPath( ): Method to get path to database.
  • getVersion( ): Method to get version of database.
  • isreadOnly( ): Tells whether database is read only or not.
  • isOpen( ): Tells whether database is open or not.
  • update( String table, Content values, String whereClause, String[] whereArgs): Used to update rows in a database.
  • releaseMemory( ): used to free memory that SQL was holding.




Cursor

Cursor is an interface which provides random read write access. Cursor object help us to retrieve anything from the database. There are many functions of Cursor class which help us in data retrieval.

  • rawQuery(): returns result set in the form of cursor object pointing to the table.
  • moveToFirst(): It moves the cursor to the first row.
  • moveToLast(): This method moves the cursor to the last row.
  • moveToNext(): This function moves the cursor to the next row.
  • move( int offset): This unction is used to move the cursor forward or backward according to the given offset value.
  • isFirst(): Checks cursor is at first row or not.
  • isLast(): Checks cursor is at last row or not.
  • isNull(): Checks cursor is pointing to null.
  • getPosition( ): This method returns current position of curser in the form of row set.
  • getString( int column ): This method returns the value of given column in the form of a string.
  • getCount(): This method returns number of rows in the cursor.

Follow next tutorial for complete Android SQLite database example, demonstrating create, update, retrieve and delete data.

Share on FacebookTweet about this on TwitterShare on LinkedInShare on Google+Digg thisPin on PinterestShare on RedditShare on StumbleUponPrint this pageEmail this to someone

Leave a Reply

2 Comments on "Android SQLite Database Introduction"

avatar
Sort by:   newest | oldest | most voted
Mike
Guest
Mike

getCunt()? Now that’s a GREAT function!

filip
Admin

LOL, apologies – will be fixed ASAP 😀 But I still believe some very expensive phones have this function build-in.

wpDiscuz