简体   繁体   English

如何在 android 上的 sqlite 中将 sqlite 导入数据库

[英]how to import .sqlite into database in sqlite on android

I am doing an app in android, I have.sqlite file in my system which is called 'ff.sqlite'.我在 android 中做一个应用程序,我的系统中有一个名为“ff.sqlite”的文件。 In the.sqlite file I have 10 tables, very large no of records for tables.在 .sqlite 文件中,我有 10 个表,表的记录非常多。 In my app(android) I place the.sqlite file in raw folder and I created a database called 'festival.db'.在我的应用程序(android)中,我将 .sqlite 文件放在原始文件夹中,并创建了一个名为“festival.db”的数据库。 Now I do not know how to import the ff.sqlite file into the festival.db.现在不知道如何将ff.sqlite文件导入festival.db。 please help me.请帮我。

res/raw/ff.sqlite

to create database I use the following code in android:要创建数据库,我在 android 中使用以下代码:

        SQLiteDatabase dbs;
    dbs = openOrCreateDatabase("festival.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);

My problem is I need all tables in the festival.db from the.sqlite file please help me.我的问题是我需要来自.sqlite 文件的festival.db 中的所有表,请帮助我。

Copy your DB file from assets folder to internal memory, then open DB and do CRUD from there:将您的 DB 文件从 assets 文件夹复制到内部 memory,然后打开 DB 并从那里执行 CRUD:

private void copyDB() throws IOException{

        InputStream myInput = m_Context.getAssets().open(DB-SQLITE_FILE_NAME_KEPT_IN_ASSET_FOLDER);
        String outFileName = "/data/data/your.package.name/databases/";
        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();

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM