Sunday, July 12, 2015

Using SQLLite for Android

What is SQLite for Android?

It is an implementation of SQL language that is presented in all devices. It is a very simple version, but it also have a lot of features to be used.

·      First of all, you will need to add on your code the android.database.sqllite package.
·      You should implement methods that create and maintain the database and tables:



·      In apps, we interact with a SQLite database using the SQLiteOpenHelper class and the SQLiteDatabase class. SQLiteOpenHelper is like a ‘Portal’ into SQLiteDatabase, it allows you to create statements into SQLiteDatabase class.
·      We use OnCreate() method to be called by the system if the database does not exist.
·      OnUpgrade() is called when the version number changes.
·      getReadlableDatabase access database in read-only mode. So, only use this method for select statements.
·      getWritableDatabase is used for Insert and Update statements.
·      Definition for column names and table names:


·      SQLiteOpenHelper creates a subclass that overrides onCreate(), onUpgrade() and onOpen() callback methods. Here it is an implementation of SQLiteOpenHelper:

·      To access your database you just need to instantiate your DB class as below:

·      Put information/ Read / Delete and Update information on database:



I hope these help you in your android implementation. Happy coding! See you next month.

Thiago Leoncio.