【问题标题】:Database fails to open in phonegap数据库无法在 phonegap 中打开
【发布时间】:2014-11-13 09:18:08
【问题描述】:

我正在尝试执行 phonegap 示例,它应该在其中创建数据库并创建表。我正在尝试从下面的链接执行 http://docs.phonegap.com/en/1.4.1/phonegap_storage_storage.md.html#Storage

下面是我的代码

  <!DOCTYPE html>
  <html>
  <head>
  <title>Contact Example</title>
  <script type="text/javascript" charset="utf-8" src="phonegap-1.4.1.js"></script>
 <script type="text/javascript" charset="utf-8">
 function datab()
 {
  alert("i m in db");
  var db = openDatabase('mydb', '1.0', 'Test DB', 2 * 1024 * 1024);
  db.transaction(function (tx) {
  tx.executeSql('DROP TABLE IF EXISTS LOGSS');
  tx.executeSql('CREATE TABLE IF NOT EXISTS file1 (id unique, log1 , log2)');
  tx.executeSql('INSERT INTO file1 (id, data) VALUES (1, "First row")');
  });
  db.transaction(function (tx) {
  tx.executeSql('SELECT * FROM file1', [], function (tx, results) {
  var len = results.rows.length, i , j;
  for (i = 0; i < len; i++){
  alert(results.rows.item(i).log1);
  alert(results.rows.item(i).log2);
  }
  }, null);
  }); 
  }
  </script>
  </head>
  <body>
  <h1>Example</h1>
  <p>Database</p>
  <input type="button" onclick="datab();">
  </body>
  </html>

当我执行此代码时,它会生成一个错误 openDatabase 未定义。我已经包含了 phonegap jar 文件。我在做什么错误?请有人帮忙。

【问题讨论】:

    标签: android cordova android-sqlite


    【解决方案1】:

    您正在开发哪个科尔多瓦版本?
    您提到的链接中的科尔多瓦版本很旧(1.4)
    当前的科尔多瓦版本是 4.0

    您需要使用window.openDatabase 而不是openDatabase。在调用数据库函数之前,您还需要等待 deviceReady 事件。

    var db = window.openDatabase
    

    更多详情请查看链接here

    编辑 1: 请查看以下链接以安装cordova。

    http://thejackalofjavascript.com/phonegap-3-cli-setup-mac-windows/

    http://coenraets.org/blog/cordova-phonegap-3-tutorial/

    http://teusink.blogspot.in/2013/07/guide-phonegap-3-android-windows.html

    http://sdk.revmobmobileadnetwork.com/phonegap_cordova.html

    http://docs.phonegap.com/en/3.5.0/guide_platforms_android_index.md.html#Android%20Platform%20Guide

    Phonegap Cordova installation Windows

    PhoneGap 3.1.0 without node / npm and command line tools

    【讨论】:

    • 我刚刚添加了 phongap-1.4.1 jar 文件,但它仍然显示错误。即使我使用旧版本也没有问题,因为我只想要一个可以保存文件名的小表[只有文件甚至没有内容]。请建议我还能做什么。或任何其他示例
    • 我从未说过我使用的是 1.4.1。我说你使用的是 1.4.1 而你应该使用 4.0 版本。我还编辑了我的答案,并为您提供了有关如何安装最新版本的 cordova 的链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-23
    • 1970-01-01
    • 2014-08-13
    • 2023-03-22
    相关资源
    最近更新 更多