Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't access pre populated SQLite database using PhoneGap/Cordova in Android
    text
    copied!<p>We are trying to create a mobile app using PhoneGap/Cordova. We need to ship this app with a pre-populated SQLite db. We are able to copy the DB using below code. But when we try to access tables from copied DB in our App we get 'No Such Table' error. Can anyone help us in identifying the cause ?</p> <p>We copied the database using the below code to data/data/package_name/databases folder.</p> <pre><code> 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)) &gt; 0) out.write(buf, 0, len); in.close(); out.close(); } </code></pre> <p>index.html The below code is used to open and access the DB</p> <pre><code> function onDeviceReady() { db = window.openDatabase("Bee_dict", "1.0", "Bee_dict", 20000); tx.executeSql('SELECT * FROM data WHERE word_id = ?', [1], querySuccess_definition, errorCB); } </code></pre> <p>Cordova version - 2.9</p> <p>Thanks.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload