Want more features on Pastebin? Sign Up, it's FREE!

SQLite Android Database

By: frozenking on May 11th, 2012  |  syntax: Java  |  size: 1.00 KB  |  views: 1,359  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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();
clone this paste RAW Paste Data