java - ActiveAndroid 使用现有数据库

标签 java android sqlite activeandroid

我正在使用 ActiveAndroid作为第三方库,以便在 android 中使用 sqlite 数据库,我在使用该库创建和使用新数据库时没有任何问题,但我不知道如何将我自己的现有数据库与该库一起使用?我想将我自己的数据库放入 Assets 文件夹并将其加载到 ActiveAndroid图书馆。

public class Application extends com.activeandroid.app.Application
{

    @Override
    public void onCreate()
    {
        super.onCreate();
        createDatabase();
    }

    private void createDatabase()
    {
        Configuration dbConfiguration = new Configuration.Builder(this).setDatabaseName("dastan.db").create();
        ActiveAndroid.initialize(dbConfiguration);

    }


    @Override
    public void onLowMemory()
    {
        android.os.Process.killProcess(android.os.Process.myPid());
        super.onLowMemory();
    }
}

最佳答案

“xArthasx”在 Issue 41 中说:

If you have the file (sqlite database) and the tables keep the same structure as the class you made in java, you should be able use the database by coping the file (sqlite database) to the assets directory (project directory) and set the AA_DB_NAME equals to the name of the file.

如果现有数据库不是使用 ActiveAndroid 创建的,您可能需要迁移数据;见Use ActiveAndroid on existing database-content .

关于java - ActiveAndroid 使用现有数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34574956/

相关文章:

java - 下载 Sun java 文档/镜像网站

android - Android 中的动画图像淡入淡出导致黑屏

c - 如何完成所有待处理的 SELECT 语句?

c# - 如何在 sqlite 表中插入复杂模型?

java - 在 Hibernate 实体中使用哪种 Java 数据类型来表示数据库中的 id 列

java - 从文本文件读取整数并存储到单独的变量中? (扫描器)

android - 图像矩形和屏幕尺寸

java - 如何以编程方式更改复选框选中的颜色

sqlite - 为给定数据定位正确 OFFSET 的最佳方法

java - AndEngine Line.onAreaTouched 未调用