Opening and Creating Databases in Android without the SQLiteHelper



You can create and open databases without using the SQLiteHelper class with the openOrCreateDatabase method on the application Context. Setting up a database is a two-step process. First, call openOrCreateDatabase to create the new database.


Then, call execSQL on the resulting database instance to run the SQL commands that will create your tables and their relationships. The general process is shown in the snippet below:


 


private static final String DATABASE_NAME = “myDatabase.db”;


private static final String DATABASE_TABLE = “mainTable”;


private static final String DATABASE_CREATE = “create table “ + DATABASE_TABLE + “ ( _id integer primary key autoincrement,” + “column_one text not null);”;


SQLiteDatabase myDatabase;


 


private void createDatabase() {


myDatabase = openOrCreateDatabase(DATABASE_NAME, Context.MODE_PRIVATE,   null);


                                       myDatabase.execSQL(DATABASE_CREATE);


}

Editor: ankita Added on: 2013-03-01 13:48:39 Total View:329







Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---