· 8 years ago · Aug 28, 2018, 05:06 PM
1how to create an array and fetch the data in sqlite database in android
2off = openOrCreateDatabase("Offline.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
3off.setVersion(1);
4off.setLocale(Locale.getDefault());
5off.setLockingEnabled(true);
6final String CREATE_TABLE_OFFLINEDATA ="CREATE TABLE IF NOT EXISTS offlinedata(spotid INTEGER, username TEXT, email TEXT);";
7off.execSQL(CREATE_TABLE_OFFLINEDATA);
8ContentValues values = new ContentValues();
9values.put("id", millis);
10values.put("name", username);
11values.put("mail", email);
12off.insert("offlinedata", null, values);
13Cursor con = off.rawQuery("select * from offlinedata" , null);
14if (con != null )
15{
16 if (con.moveToFirst())
17 {
18 do
19 {
20 int spotid = con.getInt(con.getColumnIndex("id"));
21 String first = con.getString(con.getColumnIndex("username"));
22 String middle = con.getString(con.getColumnIndex("email"));
23 }
24 while (con.moveToNext());
25 }
26 }
27 off.close();