Advertisement
frozenking

SQLite Android Database

May 11th, 2012
5,184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. Database & Table creation:
  2. SQLiteDatabase db;
  3. try{
  4.             SQLiteDatabase  dbe = SQLiteDatabase.openDatabase("/data/data/bangla.rana.fahim/databases/dictionary", null,0);
  5.             dbe.close();
  6.    }
  7.             catch(SQLiteException e){
  8.  
  9.                 db = openOrCreateDatabase("dictionary", MODE_PRIVATE, null);
  10.                 db.execSQL("CREATE TABLE IF NOT EXISTS LIST(wlist varchar,ex varchar);");                
  11.                 db.close();
  12.             }
  13.  
  14.  
  15. Inserting values in table:
  16.  
  17. db.execSQL("INSERT INTO LIST VALUES('খবর');");
  18.  
  19. After completion of work close the database as:
  20. db.close();
  21.  
  22. Retrieving data using cursor:
  23.  
  24. db = SQLiteDatabase.openDatabase("path to your database", null,0);
  25. String q = "SELECT * FROM LIST where( wlist like '"+mComposing.toString()+"%')"+"ORDER BY wlist"; //your wanted query
  26. Cursor c = db.rawQuery(q, null);
  27. c.moveToFirst();
  28. do {
  29. //do whatever you like
  30. } while (c.moveToNext());
  31.  
  32. Close cursor & database:
  33. c.close();
  34. db.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement