在phonegap android中使用预填充的sqlite数据库 [英] Working with prepopulated sqlite database in phonegap android

查看:32
本文介绍了在phonegap android中使用预填充的sqlite数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 sqlite 数据库 test_db.db,我保存在 www 文件夹中,我使用cordova cli 在本地机器上构建android 应用程序.

I have an sqlite database test_db.db i have kept in the www folder i am using cordova cli to build android app on my local machine.

当我尝试打开数据库时,它正在打开新数据库,而不是访问预填充的数据库.

when i am trying to open the database it is opening new database instead of accessing the prepopulated.

我使用以下代码对此进行了测试.

I tested this using following code.

// Open the existing database 

var db = window.sqlitePlugin.openDatabase({ name : "test_db.db" });

db.transaction(function (tx) {

   alert("database opened");

   var _strQuery = "select * from mst_users;";

   tx.executeSql(_strQuery, [], function (tx, res) {

      alert("Populated Successfully with " + res.rows.length + " Records.");

   }, CommonError);

}, CommonError, DoNothing);

并且每次我收到一个错误,即表 mst_users 不存在但它存在于预填充的数据库中.

And every time i am getting an error that table mst_users does not exist but it is there in the prepopulated db.

我已经尝试了各种方法来实现这一目标,但还是卡住了.我想访问预填充数据库中的数据.

I have tried various things for achieving this but yet stucked. I want access the data in the prepopulated database .

非常感谢任何帮助..

推荐答案

在cordova项目中打开prepopulated db,需要做3个步骤:

To open prepopulated db in cordova project, you need to do 3 steps:

  1. 将 .db 文件复制到 www 主目录

  1. Copy .db file into main www directory

安装 this 插件并使用复制方法(这将复制 .db文件到您的操作系统/设备的指定目录)

Install this plugin and use copy method(this will copy the .db file to the specified directory for your os/device)

使用这个插件打开.db文件

Use this plugin to open the .db file

就是这样... :)

这篇关于在phonegap android中使用预填充的sqlite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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