如何将现有的SQLite3数据库导入Room? [英] How do I import an existing SQLite3 database into Room?

查看:84
本文介绍了如何将现有的SQLite3数据库导入Room?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我在桌面上使用SQLite3创建了一个仅需读取某些信息的数据库.我正在制作的应用程序不需要在此表中插入或删除信息.

Okay so I used SQLite3 on desktop to create a database of certain information that need only be read. The app I am making does not need to insert or delete information from this table.

我已经在Room数据库层上进行了一些Google搜索,并且所有文档都要求在构建应用程序时在Room中创建一个新的数据库,这是我不想要的,因为我已经拥有一个数据库.

I've done a fair bit of Googling on the Room database layer and all the documentation entails creating a fresh database in Room while your app is built -- something I do not want, since I already have one.

如何让Room读取一个已经存在的数据库?我的数据库当前存储在/app/src/main/assets/splitbilldatabase.db 中.

How would I go about having Room read an already-existing database? My database is currently stored in /app/src/main/assets/splitbilldatabase.db.

推荐答案

如果您使用的是Room 2.2.0或更高版本,则可以将数据库构建器配置为从资产文件夹中加载数据库开始.

If you are using Room 2.2.0 or greater, you can configure the database builder to start by loading the DB from the assets folder.

Room.databaseBuilder(appContext, AppDatabase.class, "splitbilldatabase.db")
    .createFromAsset("splitbilldatabase.db")
    .build()

更多信息:- https://developer.android.com/training/data-storage/room/prepopulate

这篇关于如何将现有的SQLite3数据库导入Room?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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