如何更换一个SQLite数据库数据库、SQLite

2023-09-05 09:07:59 作者:帘卷笙声寂

有没有办法来取代一个完整的SQLite数据库?我期待在建立一个应用程序,它拥有大量的数据,我需要能够更新它。幸运的是我能够验证数据库结构不会改变,只是数据。是否有这样做的清洁方法吗?

Is there a way to replace a complete SQLite DB? I'm looking at building an app which holds a lot of data and I need to be able to update it. Fortunately I am able to verify that the DB structure won't change, just the data. Is there a clean way of doing this?

- 编辑 -

道歉 - 我需要增加更多的细节:

Apologies - I need to add more detail:

为了更新应用程序中的数据,该计划是只需更换这将是从服务器的地方抓起数据库。所以,我不会使用 onUpgrade 或手动添加数据 - 我想转储现有的文件和复制一个新的文件来替换旧的。

In order to update the data in the app, the plan is to just replace the DB which will be grabbed from a server somewhere. So I won't be using the onUpgrade or adding data manually - I want to dump the existing file and copy a new file in to replace the old one.

我觉得一个数据库通常会被保存在/数据/数据​​/ YOUR_PACKAGE /数据库/,我有机会获得该目录?在这种情况下,我可以JST从服务器下载的文件,并复制它在上面(显然确保没有什么是第一次访问该文件等)

I think a DB will normally be stored in "/data/data/YOUR_PACKAGE/databases/", do I have access to this directory? In which case can I jst download the file from the server and copy it over the top (obviously making sure that nothing is accessing the file first etc)

推荐答案

这个问题是和我的一样:Can我下载一个SQLite数据库在/ SD卡,并从我的Andr​​oid应用程序访问它?

This question is the same as mine : Can I download an SQLite db on /sdcard and access it from my Android app?

File dbfile = new File("/sdcard/mydb.sqlite" ); 
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
System.out.println("Its open? "  + db.isOpen());