lundi 10 août 2015

SQLite database is recreated?

This question may be repeated but i tried most of the answers of stack overflow to solve my problem but my problem is not solved yet. I am creating table and inserting value by searching devices in the area but whenever i restart the app the previously stored devices are not listing there and the devices are inserting like first time inserting My database code is

public class DBHelper extends SQLiteOpenHelper {
private static DBHelper dbHelper = null;
private static final String DATABASE_NAME = "Demo";
private static final int DATABASE_VERSION = 1;
private Context context;

private static final String TABLE_CREATE_DEVICES = "CREATE TABLE IF NOT EXISTS Devices"
        + "(Id INTEGER PRIMARY KEY AUTOINCREMENT," + "deviceId VARCHAR NOT NULL UNIQUE,"
        + "img VARCHAR DEFAULT NULL)";

public static DBHelper getInstance(final Context context) {
    if (dbHelper == null) {
        dbHelper = new DBHelper(context.getApplicationContext());
    }
    return dbHelper;
}

public DBHelper(final Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
    this.context = context;
}

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
    sqLiteDatabase.execSQL(TABLE_CREATE_DEVICES);
}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}

I am inserting value using the following lines

db.execSQL("INSERT INTO Devices(deviceId, img) values('" + device + "','"+ img + "')");

When i restart the app previously added device inthe table are not showing it is inserted again

Aucun commentaire:

Enregistrer un commentaire