How to create a SQLite Database in Android using the API -
i unable create new database using api
sqlitedatabase.openorcreate(string path,cursorfactory factory);
when using api, it's throwing exception
unable open database file
please me how fix exception.
suppose want create table "settings" table , "mydb.db". use class create db , tables
public class mydbconnector extends sqliteopenhelper { private static final string tag = "mydbconnector"; public mydbconnector(context context) { super(context, "mydb.db", null, 3); } @override public void oncreate(sqlitedatabase db) { db.execsql("create table " + constants.table_settings + " (" + constants.table_settings_field_key + " text primary key, " + constants.table_settings_field_value + " text);" ); } }
and read/write in db use,
sqlitedatabase db = new mydbconnector(this).getreadabledatabase(); //to read tables in db sqlitedatabase db = new mydbconnector(this).getwritabledatabase(); // write in db
Comments
Post a Comment