SQLite Database Management in Android

Creating Database

SQLiteDatabase db;

db = openOrCreateDatabase(“my_sqlite_database.db”,  SQLiteDatabase.CREATE_IF_NECESSARY,null);

Creating Table

String s = “CREATE TABLE tbl_authors (id INTEGER PRIMARY KEY AUTOINCREMENT,firstnameTEXT,lastname TEXT);”;

db.execSQL(s);

Inserting data to the table

Method : 1

db.execSQL( “insert into tbl_authors(firstname, lastname) values (‘Yashvant‘, ‘Kanetkar‘ );” );

Method : 2

ContentValues values = new ContentValues();

values.put(“firstname“, “Yashvant“);

values.put(“lastname“, “Kanetkar“);

db.insert(“tbl_authors”, null, values);

Updating data to the table :

Updating data to the table :

Method : 1

db.execSQL(“update tbl_authors set firstname=’I’ where lastname=’Bayross‘;”);

Method : 2

ContentValues values = new ContentValues();

values.put(“firstname“, “Y”);

db.update(“tbl_authors”, values, “lastname=?”, new String[] {“Kanetkar“});

Deleting data from the table :

Method : 1

db.execSQL(“delete from tbl_authors where firstname=’I'”);

Method : 2

db.delete(“tbl_authors”, “firstname=?”, new String[]{“Y”});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s