【问题标题】:Sqlite database import exportSqlite 数据库导入导出
【发布时间】:2018-04-12 07:34:58
【问题描述】:

我可以导入和导出 SQLite 数据库吗?意味着我只想携带数据库。 .DB 文件将放在我的 SD 卡上。该应用程序将从 sd 卡的数据库中获取数据并将数据写入该数据库。使用该应用程序后。关闭应用程序并将.db 文件带到其他设备,并能够查看以前的数据并可以操作该数据库。

【问题讨论】:

  • Sqlite 不会写入 sd 卡上的数据库文件。仅限于内部私有数据库目录中的文件。但是您可以将该文件复制到 sd 卡,然后将卡带到其他设备。目前尚不清楚您想如何将文件传输到另一台设备。
  • 鉴于您编写代码以根据表和实体访问相同的数据库,是的,可以这样做。
  • 我只想用一个按钮来浏览 sd 卡中的 .db 文件。然后,将该 .db 文件复制到应用程序 SQLite 数据库。使用该数据库并在 Android 数据文件夹中操作数据库上的数据后,然后将其导出。
  • 意思是,我在数据库浏览器的帮助下创建了一个名为“student.DB”的数据库。该数据库将像可移动的 sd 卡一样放入外部存储中。然后,应用程序上的一个按钮将允许用户从 sd 卡浏览该数据库。然后,从 sd 卡复制该数据库并使用该应用程序。当我将关闭应用程序数据库将被导出到 sd 卡。表示我将输入学生的姓名“Vivek”。可以在其他设备上看到

标签: android


【解决方案1】:

您可以使用 ORM 获取 SD 卡中的数据库文件。但不使用默认的 SQLiteOPenHelper。

检查 Litepal 框架:有关更多信息,请查看 https://github.com/LitePalFramework/LitePal

        Define where the .db file should be. "internal" means the .db file
        will be stored in the database folder of internal storage which no
        one can access. "external" means the .db file will be stored in the
        path to the directory on the primary external storage device where
        the application can place persistent files it owns which everyone
        can access. "internal" will act as default.
        For example:
        <storage value="external" />

【讨论】:

    猜你喜欢
    • 2019-11-12
    • 2013-05-08
    • 1970-01-01
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多