mercredi 2 septembre 2015

SQLite Database not working for android 5.1

I have a simple SQLite database with a table having 2 columns, I just fetch data from the table using: select * from myprofile;

This code works in pre 5.0 android properly, but doesnt work on 5.0 or 5.1 android. Are there any changes to the normal select statement. I checked their documentation but couldnt find anything related to this

public void chkFirstTime()
{
    SQLiteDatabase sampleDB1 = null;
    Cursor c = null;
    try {
        sampleDB1 =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);

         sampleDB1.execSQL("CREATE TABLE IF NOT EXISTS myprofile (username Text,useremail Text);" );
         Log.w("table created", "table created");

          c = sampleDB1.rawQuery("SELECT username,useremail FROM myprofile", null);
          count= 0;


        if (c != null ) {
            if  (c.moveToFirst()) {
                do {

                    username1 = c.getString(c.getColumnIndex("username"));
                    Email1 = c.getString(c.getColumnIndex("useremail"));

                    count = count + 1;

                }while (c.moveToNext());
            } 
        }


    } catch (SQLiteException se ) {
        Log.e(getClass().getSimpleName(), "Could not create or Open the database1 in check_if_exists");
    } finally {
        if (sampleDB1 != null) 
                sampleDB1.close();
    }

}

Aucun commentaire:

Enregistrer un commentaire