Skip to main content

Posts

Showing posts with the label sqlite table

Modify records in SQLite in ANDROID

For COMPLETE TUTORIALS see here : in DABASEHELPER CLASS : ContentValues cvupdate = new ContentValues(); // Bundle for writting the database fields cvupdate.put(KEY_NAME, namestr);// put the values passed to ContentValues cvupdate.put(KEY_NICKNAME, nickstr);// put the values passed to ContentValues db.update(DATABASE_TABLE, cvupdate, KEY_ROWID + "=" + smodify, null);// specify where to be changed in sqlite.java : String Namestr = editName.getText().toString(); String Nickstr = editNickName.getText().toString(); String smodify =editinfo.getText().toString(); long lmodify =Long.parseLong(smodify); DBAdapter adaptmodify =new DBAdapter(SQliteExample.this); adaptmodify.open(); adaptmodify.updateentry(lmodify,Namestr,Nickstr); // pass index and new values to be inserted adaptmodify.close();

Delete records from SQLite table in ANDROID

For COMPLETE TUTORIALS see here : in DABASEHELPER CLASS : public void deleteentry(long ldelete) { // TODO Auto-generated method stub db.delete(DATABASE_TABLE, KEY_ROWID + "=" +ldelete, null); } in Sqlite.java : String sdelete =editinfo.getText().toString(); long ldelete =Long.parseLong(sdelete); DBAdapter adaptdelete =new DBAdapter(SQliteExample.this); adaptdelete.open(); adaptdelete.deleteentry(ldelete); //pass the index to be deleted adaptdelete.close();

Insert records in SQLite tables in ANDROID

For COMPLETE TUTORIAL see here : in DABASEHELPER CLASS : public void entryfield(String namestr, String nickstr) { ContentValues cv = new ContentValues(); // Bundle for writting the database fields cv.put(KEY_NAME, namestr);// put the values passed to ContentValues cv.put(KEY_NICKNAME, nickstr);// put the values passed to ContentValues db.insert(DATABASE_TABLE, null, cv);// insert into databse with vlues as "content vales" } in sqlite.java //==Create an object of adapter class to call methods== DBAdapter Entryadapter = new DBAdapter(SQliteExample.this); Entryadapter.open(); Entryadapter.entryfield(Namestr,Nickstr); // Calling the function in DBAdapter Class Entryadapter.close();

Simple SQLite Example in Android

See more basics on Android along with interview questions DBAdapter.java (DABASEHELPER CLASS) import android.content.ContentValues; import android.content.Context; import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; public class DBAdapter { public static final String KEY_ROWID = "id"; public static final String KEY_NAME = "title"; public static final String KEY_NICKNAME = "duedate"; private static final String DATABASE_NAME = "assinDB.db"; private static final String DATABASE_TABLE = "assignments"; private static final int DATABASE_VERSION = 2; private final Context context; private DatabaseHelper ObjectDBHelper; private SQLiteDatabase db; public DBAdapter(Context ctx) { context = ctx; } private static class DatabaseHelper extends SQLiteOpenHelper { public DatabaseHelper(Context ...