background preloader

Android SQLite Database and ContentProvider

Android SQLite Database and ContentProvider

Using SQLite Database with Android Download demo - 86.1 KB Introduction Android default Database engine is Lite. SQLite is a lightweight transactional database engine that occupies a small amount of disk storage and memory, so it's a perfect choice for creating databases on many mobile operating systems such as Android, iOS. Things to consider when dealing with SQLite: Data type integrity is not maintained in SQLite, you can put a value of a certain data type in a column of another datatype (put string in an integer and vice versa). In this tutorial, we will create a simple database application to store employees data. the DB has: Tables Employees Dept Views ViewEmps: to display employees and their relative departments. Creating SQLite Database By default, SQLite on Android does not have a management interface or an application to create and manage databases from, so we're going to create the database ourselves by code. Our class will have the following members: Hide Copy Code The Constructor Creating the Database instead of 1: Notes

Using your own SQLite database in Android applications | ReignDesign Most all of the Android examples and tutorials out there assume you want to create and populate your database at runtime and not to use and access an independent, preloaded database with your Android application. The method I'm going to show you takes your own SQLite database file from the "assets" folder and copies into the system database path of your application so the SQLiteDatabase API can open and access it normally. 1. Preparing the SQLite database file. Assuming you already have your sqlite database created, we need to do some modifications to it. Open your database and add a new table called "android_metadata", you can execute the following SQL statement to do it: CREATE TABLE "android_metadata" ("locale" TEXT DEFAULT 'en_US') Now insert a single row with the text 'en_US' in the "android_metadata" table: INSERT INTO "android_metadata" VALUES ('en_US') , then selecting the table you want to edit and finally selecting the field you want to rename. 2. That's it. ...

Android - Accessing Data With Android Cursors - Android Tutorials SQLite is an open-source server-less database engine. SQLite supports transacations and has no configuration required. SQLite adds powerful data storage to mobile and embedded apps without a large footprint. First import android.databse.sqlite.SQLiteDatabase into your application. Then use the openOrCreateDatabase() method to create or connect to a database. package higherpass.TestingData; import android.app.Activity; import android.os.Bundle; import android.database.sqlite.SQLiteDatabase; public class TestingData extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); SQLiteDatabase db; db = openOrCreateDatabase( "TestingData.db" , SQLiteDatabase.CREATE_IF_NECESSARY , null ); } } Add the android.database.sqlite.SQLiteDatabase to the standard imports from the new project. The Google Android SDK comes with a utility adb. db.delete("tbl_states", "id=?"

Related: