2016-01-08 127 views
0

我有一個sqlite數據庫test_db.db我保存在www文件夾中,我使用cordova cli在本地機器上構建android應用程序。在phonegap中使用預填充的sqlite數據庫android

當我試圖打開數據庫,它正在打開新的數據庫,而不是訪問預填充。

我使用下面的代碼測試了這個。

// 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不存在,但它是在prepopulated分貝。

我已經嘗試了各種各樣的東西來達到這個目標,但還是陷入困境。我想要訪問預填充數據庫中的數據。

任何幫助真的很感謝..

+0

檢查此鏈接:http://gauravstomar.blogspot.in/2011/08/prepopulate-sqlite-in-phonegap.html – Ved

回答

0

你好,我得到了這個問題的解決方案。

而在folling代碼打開數據庫

變種分貝= window.sqlitePlugin.openDatabase({名: 「test_db.db」});

添加參數這樣

變種分貝= window.sqlitePlugin.openDatabase({名: 「test_db.db」,createFromLocation:1});

然後它將採取您已經保存在www文件夾中的數據庫。

1

科爾多瓦的項目中打開預先填充數據庫,你需要做的3個步驟:

  1. 複製.db文件到主目錄www

    安裝this插件,並利用複製方法(這將複製.db文件 到指定的目錄,在OS /設備)

    使用this插件打開.db文件

完蛋了... :)

相關問題