使用预填的sqlite数据库在phonegap android [英] Working with prepopulated sqlite database in phonegap android
问题描述
我有一个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不存在, db。
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项目中打开预填充的数据库,您需要执行以下3个步骤:
To open prepopulated db in cordova project, you need to do 3 steps:
-
复制.db文件到主www目录
Copy .db file into main www directory
安装这个插件和使用复制方法(这将复制.db文件
到您的os /设备的指定目录)
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
它是...:)
这篇关于使用预填的sqlite数据库在phonegap android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!