PhoneGap + android,预填充数据库无法正常工作。

时间:2012-02-13 04:22:47

标签: android database cordova populate

我正在创建一个PhoneGap(android)项目。在这里,我从一个文本文件填充数据库表。 (比如我的包名是com.santu.jdictionary)。但是当我尝试将此0000000000000001.db以及Databases.db文件复制到/data/data/com.santu.jdictionary/app_database/file__0/文件夹时,我收到错误。

 void copy(String file, String folder) throws IOException 
  {

   File CheckDirectory;
   CheckDirectory = new File(folder);
   if (!CheckDirectory.exists())
   { 
    CheckDirectory.mkdir();
   }

      InputStream in = getApplicationContext().getAssets().open(file);
      OutputStream out = new FileOutputStream(folder+file);

      // Transfer bytes from in to out
      byte[] buf = new byte[1024];
      int len; while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
      in.close(); out.close();

  }

其次,我已经能够通过phoneGap插件将此文件成功复制到上述文件夹,但复制后PhoneGap也无法使用此文件。 当我尝试使用此代码打开数据库时,会初始化一个新的.db文件(即0000000000000002.db)

 db = window.openDatabase("database", "1.0", "JDictionary", 10000000);
 db.transaction(populateDB,errorCB, successCB);

那我在哪里弄错了。

提前感谢。

santu ghosh

1 个答案:

答案 0 :(得分:0)

我最终在::

中找到了解决方案

link

我希望每个评论过的人都会在尝试帮助他人之前阅读这篇文章