Example of creating a database on Android using Sqlite:
public class FeedReaderDbHelper extends SQLiteOpenHelper {
// If you change the database schema, you must increment the database version.
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "FeedReader.db";
public FeedReaderDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(SQL_DELETE_ENTRIES);
}
}
Reference: http://developer.android.com/training/basics/data-storage/databases.html
In SQL_CREATE_ENTRIES
you inform the SQL DML commands for creating tables, fields, changing and removing fields.
The method onCreate
will be called when there is an interaction with the Sqlite database and the database has not been created yet on the device.
The method onUpgrade
will be called when there is an interaction with the Sqlite database, the database has already been created on the device, but the application on the device has been updated and the database is in another version.
You can put several db.execSQL
one below the other for creating a certain table, changing a certain field, as you prefer.
There is also the possibility that Android communicate externally through Webservices with a server that presents a database, such as Mysql, Postgresql, Mongodb (Nosql, document-oriented database) using Java, PHP, or other programming language to perform the communication, usually the REST architecture is used and returns JSON to the application.
Other useful links:
http://www.tutorialspoint.com/android/android_sqlite_database.htm
http://developer.android.com/reference/android/database/sqlite/SQLiteDatabase.html
https://www.sqlite.org/docs.html
http://json.org/
http://www.infoq.com/br/articles/rest-introduction
Look at this one of mine reply in the Soen.
– ramaral