askIT

Android SQLite database

sqlite.png Android supports database the database system SQLite. It is very similar to all other databases, so if you've worked with for example. MySQL then you know the basics.

SQLite is a popular database. It is used by many applications that are built up by a client and a local part, eg. browsers. It is also used by operating systems and embedded systems.

DBAdapter

All applications for Android that are using databasse needs a separate class called DbAdapter. This class contains the layout of the database, and all queries.

The procedure for DBAdapter is:

/* Open DBAdapter */
DBAdapter db = new DBAdapter(this);

/* Open db */
db.open();

/* Queries */
// Queries to the database here

/* Close db */
db.close();

SQLiteBrowser

You will need the program SQLiteBrowser to see data stored in the database. SQLiteBrowser can not see the data stored in the database in real time. You must download the database file from your Android device and then have a look at it. After doing changes you need to download the database file again.

First you need to start your project by clicking the Run run.jpg.

Then browse to the Android Device Monitor. This can be found under
"Tools -> Android > Android Device Monitor".

01_android_device_monitor.jpg

Scroll looked forward to "/data/data/databases". Proceed to your package, below is the example package "com.nettport.notatblokk". Here is the database mydb. This can be downloaded at clicking "Pull a file from this device".

02_android_device_monitor.jpg

Start up sqlitebrowser and choose Open Database. Then select the database file and you can now see the tables and content in the database.

03_db_browser_for_sqlite_open_database.jpg

04_browse_data.jpg

Add comment

avatar_blank_60.png

Comment:

Name:

Email:

Comments

No comments yet. You can be the first one to comment. Just write your comment in the form and click on the submit button.