Sqlite数据库无法在android中打开 [英] Sqlite database unable to open in android

查看:141
本文介绍了Sqlite数据库无法在android中打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序我已经使用sqlite数据库。我可以插入数据库中的值,但是当我想从数据库检索值,它给我的异常数据库不是开放的。我在这里附上我的代码。

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; 


推荐答案

U打开打开的ur数据库并尝试检索数据这是为什么异常来了,只是尝试打开数据库like,

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

db = DBHelper.getWritableDatabase();

这篇关于Sqlite数据库无法在android中打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆