android - LG手机无法访问SqLite数据库

标签 android database sqlite sqliteopenhelper lg

我们已经为 Android 平台开发了一个预加载了 SQLite 数据库的应用程序。使用 SQLiteOpenHelper,在第一次执行应用程序时,我们从“Assets”复制数据库到应用程序数据目录(/data/data/br.com.lwu/databases/appdatabase.sqlite)。 这适用于大多数设备。但我们在使用 LG 手机时遇到以下问题:

  • LG Optimus One
  • LG-P500
  • LG-P500h

显然,数据库已正确复制。但是应用程序不能访问数据库(比如表)。 我们需要帮助!

// Copy Database:

    private static String DB_PATH = "/data/data/br.com.lwu/databases/";
    private static String DB_NAME = "appdatabase.sqlite";


private void copyDataBase() throws IOException{
        InputStream myInput = myContext.getAssets().open(DB_NAME);

        String outFileName = DB_PATH + DB_NAME;
        OutputStream myOutput = new FileOutputStream(outFileName);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0){
            myOutput.write(buffer, 0, length);
        }

        myOutput.flush();
        myOutput.close();
        myInput.close();

    }


public void openDataBase() throws SQLException{ 
        String myPath = DB_PATH + DB_NAME;

        if (myDataBase == null) {
            myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);
        }

    }

 @Override
    public synchronized void close() {

        super.close();

        if (myDataBase != null)
            if (myDataBase.isOpen()) {
                myDataBase.close();
                myDataBase = null;

            }

    }    

最佳答案

尝试改变:

myDataBase = SQLiteDatabase.openDatabase(myPath, null,
            SQLiteDatabase.OPEN_READWRITE);

对此:

myDataBase = SQLiteDatabase.openDatabase(myPath, null,
          SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.NO_LOCALIZED_COLLATORS);

这样做不需要您拥有 android vm 所需的强制表 android_metadata,以防它在您的数据库中丢失。

关于android - LG手机无法访问SqLite数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11049889/

相关文章:

mysql - 从 Sql 数据库迁移到 NoSql 数据库的限制

ios - 如果列存在则更改表,如果不存在则添加

python - Django for循环显示数据库中的所有对象

c# - 在 UWP 中使用 SQLite-PCL 检查表是否存在

Android SimpleDateFormat 无法解析日期时间(在 sun 1.6 jre 上工作正常)

Android:是否可以将 ZIP 文件添加为原始资源并使用 ZipFile 读取它?

从 MYSQL 结果建立链接的 PHP 脚本?

mysql - MemSQL - 跨主节点和叶节点清除计划缓存

android - 从 DatePickerDialog 中删除标题

android - 按钮栏与回收站 View 问题重叠