我們正在嘗試使用PhoneGap/Cordova創建移動應用程序。我們需要使用預填充的SQLite數據庫來發布此應用程序。我們可以使用下面的代碼複製數據庫。但是當我們嘗試在我們的應用程序中訪問複製數據庫中的表時,我們得到'沒有這樣的表'的錯誤。任何人都可以幫助我們找出原因嗎?無法使用Android中的PhoneGap/Cordova訪問預填充的SQLite數據庫
我們使用以下代碼將數據庫複製到data/data/package_name/databases文件夾。
try
{
File dbFile = getDatabasePath("Bee_dict.db");
if(!dbFile.exists()){
this.copy("Bee_dict.db",dbFile.getAbsolutePath());
}
}
catch (Exception e)
{
e.printStackTrace();
}
//And our copy function:
void copy(String file, String folder) throws IOException
{
File CheckDirectory;
CheckDirectory = new File(folder);
String parentPath = CheckDirectory.getParent();
File filedir = new File(parentPath);
if (!filedir.exists()) {
if (!filedir.mkdirs()) {
return;
}
}
InputStream in = this.getApplicationContext().getAssets().open(file);
File newfile = new File(folder);
OutputStream out = new FileOutputStream(newfile);
byte[] buf = new byte[1024];
int len; while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
in.close(); out.close();
}
的index.html 下面的代碼是用來打開和訪問數據庫
function onDeviceReady()
{
db = window.openDatabase("Bee_dict", "1.0", "Bee_dict", 20000);
tx.executeSql('SELECT * FROM data WHERE word_id = ?', [1], querySuccess_definition, errorCB);
}
科爾多瓦版本 - 2.9
感謝。
在糖果和ics工作正常,但不工作在薑餅。 – KratosBala
https://github.com/lite4cordova/Cordova-SQLitePlugin。 這個插件工作完美。 – KratosBala
謝謝@KratosBala更新鏈接:https://github.com/brodysoft/Cordova-SQLitePlugin – bschandramohan