Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite database with device
    primarykey
    data
    text
    <p>In my android application, I use SQLite database. It works only for emulator. When I'm installing my apk file into device, It won't show any data. But in my emulator it works very well. I can't understand about this problem. </p> <p>1) Do I copy anything to device to make it work? </p> <p>2) Is the database I created common for all? </p> <p>3) Do I backup the database for every new user?</p> <p>Someone explain please</p> <pre><code>public class SQLiteAdapterv { public static final String MYDATABASE_NAME2 = "MY_DATABASE2"; public static final String MYDATABASE_TABLE2 = "MY_VLGMAS"; public static final int MYDATABASE_VERSION = 1; public static final String KEY_ID = "_id"; public static final String KEY_CONTENT1 = "Content1"; public static final String KEY_CONTENT2 = "Content2"; public static final String KEY_CONTENT3 = "Content3"; public static final String KEY_CONTENT4 = "Content4"; public static final String KEY_VCODE = "vcode"; public static final String KEY_VNAME = "vname"; public static final String KEY_DIVSEC= "divsec"; private static final String SCRIPT_CREATE_DATABASE1 = "create table " + MYDATABASE_TABLE2 + " (" + KEY_ID + " integer primary key autoincrement, " + KEY_VCODE + " text not null, " + KEY_VNAME + " text not null," + KEY_DIVSEC + " text not null);"; private SQLiteHelper sqLiteHelper; private SQLiteDatabase sqLiteDatabase; private Context context; public SQLiteAdapterv(Context c) { context=c; } public SQLiteAdapterv openToRead() throws android.database.SQLException { sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME2, null, MYDATABASE_VERSION); sqLiteDatabase = sqLiteHelper.getReadableDatabase(); return this; } public SQLiteAdapterv openToWrite() throws android.database.SQLException { sqLiteHelper = new SQLiteHelper(context, MYDATABASE_NAME2, null, MYDATABASE_VERSION); sqLiteDatabase = sqLiteHelper.getWritableDatabase(); return this; } public void close(){ sqLiteHelper.close(); } public long insert(String vcode, String vname,String divsec){ ContentValues contentValues = new ContentValues(); contentValues.put(KEY_VCODE, vcode); contentValues.put(KEY_VNAME, vname); contentValues.put(KEY_DIVSEC, divsec); return sqLiteDatabase.insert(MYDATABASE_TABLE2, null, contentValues); } public int deleteAll(){ return sqLiteDatabase.delete(MYDATABASE_TABLE2, null, null); } public Cursor queueAll(){ String[] columns = new String[]{KEY_ID, KEY_VCODE, KEY_VNAME,KEY_DIVSEC}; Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE2, columns, null, null, null, null, null); return cursor; } public String getDivSec(String vname) { Cursor c=sqLiteDatabase.rawQuery("SELECT * FROM " + MYDATABASE_TABLE2 + " WHERE "+KEY_VNAME +"='"+ vname+"'",null); c.moveToFirst(); String divsec=""; if (c!=null) { divsec=c.getString(3); } c.close(); return divsec; } public String[] getAllVillage() { int i=0; Cursor c=sqLiteDatabase.rawQuery("SELECT * FROM " + MYDATABASE_TABLE2 ,null); String[] villagelist=new String[c.getCount()]; if (c.moveToFirst()) { do { villagelist[i]=c.getString(2); i++; }while(c.moveToNext()); } c.close(); return villagelist; } public String getVcode(String vname) { Cursor c=sqLiteDatabase.rawQuery("SELECT * FROM " + MYDATABASE_TABLE2 + " WHERE "+KEY_VNAME +"='"+ vname+"'",null); c.moveToFirst(); String vcode=""; if (c!=null) { vcode=c.getString(1); } c.close(); return vcode; } public class SQLiteHelper extends SQLiteOpenHelper { public SQLiteHelper(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); // TODO Auto-generated constructor stub } @Override public void onCreate(SQLiteDatabase db) { // TODO Auto-generated method stub db.execSQL(SCRIPT_CREATE_DATABASE1); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload