Kushal
Kushal

Reputation: 3

Sqlite database unable to open in android

in my application i have used sqlite database. I am able to insert the values in the database but when i want to retrieve the value from the database it gives me exception database is not open .I attach my code here.

db = openOrCreateDatabase("TaskTower.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
        try{

         /*db = openOrCreateDatabase("TaskTower.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
         db.setVersion(1);
         db.setLocale(Locale.getDefault());
         db.setLockingEnabled(true);*/

        //db.execSQL("SELECT * FROM dummytt1");
        Cursor cur = db.query("dummyTT1", 
                null, null, null, null, null, null);
        cur.moveToFirst();

        while (cur.isAfterLast() == false){ 
                ans[i] = new String();
                ans[i] = "";
                ans[i] = cur.getString(1)+"~"+cur.getString(2);

                System.out.println("The Offline Data is :"+ans[i]);
                i++;

            cur.moveToNext();      
        }
        cur.close();
        }

        catch (Exception e) {
            System.out.println("The Error Caused  Is :"+e);
        }

        return ans; 

Upvotes: 0

Views: 957

Answers (1)

Jyosna
Jyosna

Reputation: 4446

U didnt open open ur database and trying to retrieve data thats why exception came, just try to open database like,

db = DBHelper.getWritableDatabase();

Upvotes: 1

Related Questions