SQLite Android。无法打开数据库文件 [英] SQLite Android . unable to open database file

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

问题描述

我发现了很多关于这个问题的问题,但我不能解决它。
我在assets文件夹中有一个sqlite db:

I found a lot of question about this problem, but i can't fix it. I have a sqlite db in assets folder:

assets/data/data/{package_name}/databases/mydb.db



我可以在更改一个表结构之前打开数据库和读取数据。我尝试卸载应用程序,并重新安装,但我得到相同的异常。

I can open database and read data before change one table structure. I try to uninstall the app and reinstall again, but i get the same exception.

我现在可以做什么?

提前感谢

EDIT

// The Android's default system path of your application database.
private static String DB_PATH = "/data/data/{mypagackename}/databases/";

private static String DB_NAME = "mydb.db";

打开数据库(在更改表结构之前,添加一些字段,它不起作用)

Open database (Before change table structure, adding some fields, it doesn't work)

public void openDataBase() throws SQLException {

    // Open the database
    String myPath = DB_PATH + DB_NAME;
    myDataBase = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READONLY);

}


推荐答案

本教程

它解释如何使用预加载的数据库。基本上你不能使用数据库权限从资产,你必须将其复制到内部数据存储,然后从那里打开

It Explains how to work with preloaded database. Basically you can't use database right from the assets, you have to copy it over into internal data storage first and open it from there

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

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