background preloader

Database, SQLite

Facebook Twitter

Android - Accessing Data With Android Cursors - Android Tutorials. SQLite is an open-source server-less database engine.

Android - Accessing Data With Android Cursors - Android Tutorials

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. Create a new project in Eclipse called TestingData and select the API version of your choice. 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 ); } } The Google Android SDK comes with a utility adb.

Android SQLite Database Tutorial. Android SQLite Database and ContentProvider. Using SQLite Database with Android. Download demo - 86.1 KB Introduction Android default Database engine is Lite.

Using SQLite Database with Android

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. Android SQLite Database. Using your own SQLite database in Android applications. 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.

Using your own SQLite database in Android applications

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. If you don't have a sqlite manager I recommend you to download the opensource SQLite Database Browser available for Win/Linux/Mac. 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')