使用 Javascript 的 Phonegap-Android-sqlite。如何连接?

发布于 2024-10-24 08:36:31 字数 342 浏览 2 评论 0原文

我是 Android-Phonegap 开发新手。我正在 Windows XP 中使用 Eclipse 创建一个项目。 我正在使用 sqlite 数据库。我看到了文档中的示例代码。但我无法执行这个例子。我没有得到所需的结果。

假设我想以表格格式 HTML 获取表演示中的所有条目。 index.html 中的代码是什么?为此,程序是什么?执行此操作的步骤是什么?或者还有什么更好的教程可以帮助我做到这一点?

预先感谢

Dnyan。

I am new to Android-Phonegap dev. I am creating a project using Eclipse in Windows XP.
I am using sqlite database. I saw the sample code in the docs. But I'm not able to execute this example. I am not getting the required results.

Suppose I want to get all the entries in the table demo in tabular format, HTML. What will the code be in index.html? For that, what is the procedure and what is the step by step procedure for doing this? Or else any better tutorials which help me to do this?

Thanks in Advance

Dnyan.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

圈圈圆圆圈圈 2024-10-31 08:36:31

在 main.js 中,您将其添加

rowsDataHandler = function(transaction, results) {
    // Handle the results
    var html = "<ul>";
    for (var i=0; i<results.rows.length; i++) {
        var row = results.rows.item(i);
        html += '<li>'+row['data']+'</li>\n';
    }
    html +='</ul>';
    document.getElementById("mydata").innerHTML = html;
}
// load the currently selected icons

loadRows = function(db) {
    try {
        db.executeSql('SELECT * FROM DEMO',[], rowsDataHandler, errorCB);
    } catch(e) {alert(e.message);}
}   

到 index.html 中,您将这一行添加到正文中

<div id="mydata"></div>

in main.js you add this

rowsDataHandler = function(transaction, results) {
    // Handle the results
    var html = "<ul>";
    for (var i=0; i<results.rows.length; i++) {
        var row = results.rows.item(i);
        html += '<li>'+row['data']+'</li>\n';
    }
    html +='</ul>';
    document.getElementById("mydata").innerHTML = html;
}
// load the currently selected icons

loadRows = function(db) {
    try {
        db.executeSql('SELECT * FROM DEMO',[], rowsDataHandler, errorCB);
    } catch(e) {alert(e.message);}
}   

in index.html you add this row inside body

<div id="mydata"></div>
智商已欠费 2024-10-31 08:36:31

需要记住的一件事是,如果您不是在设备或模拟器上测试应用程序,而是在 Chrome 或 Safari 等浏览器中测试应用程序,则该应用程序

document.addEventListener("deviceready", onDeviceReady, false);

将无法工作。我所做的就是注释掉这一行,然后调用

onDeviceReady(); 

当我然后在模拟器中测试时,我取消注释“文档...”行并注释掉

onDeviceReady();

One thing to bear in mind is that if you aren't testing the application on a device or in an emulator, but rather in a browser like Chrome or Safari,

document.addEventListener("deviceready", onDeviceReady, false);

won't work. What I've done is to comment out this line and just to put in a call to

onDeviceReady(); 

When I then test in the emulator I uncomment the "document…" line and comment out

onDeviceReady();
恏ㄋ傷疤忘ㄋ疼 2024-10-31 08:36:31
 **html**

  <input id="show" type="button" value="Show">

 **js**

 function globalError(tx, error)
   {
     alert("Error: " + error.message);
   }

 var db = window.openDatabase('TabOrder', '', 'Bar Tab Orders', 2500000);
 db.transaction(function(tx) {
 tx.executeSql('DROP TABLE IF EXISTS SubmiteData;', null, null, globalError);
 tx.executeSql('CREATE TABLE IF NOT EXISTS SubmiteData (SubmiteDataId integer 
 primary  key, UserId text, AuthNo number, LocId number,ProdId number, 
 CardId number, OrgLat text, OrgLng text, OrgTime text)', 
          null, 
          function()
          {
            SubmiteData("USER1",12345678,23434, 21212, 220232,
            "9", "45", "23/06/2014");

          },
          globalError);
     });

    function SubmiteData(UserId, AuthNo, LocId,ProdId, CardId, OrgLat, OrgLng, OrgTime){
    db.transaction(function(tx){
    tx.executeSql('INSERT INTO SubmiteData(UserId, AuthNo, LocId, ProdId, CardId, 
    OrgLat, OrgLng, OrgTime) VALUES (?,?,?,?,?,?,?,?)', [UserId, AuthNo, LocId,
    ProdId, CardId, OrgLat, OrgLng, OrgTime], 
            null,
            globalError
           );
     });
  }


   function read(UserId, AuthNo, LocId,ProdId, CardId, OrgLat, OrgLng, OrgTime){

   db.transaction(function(tx) {
   tx.executeSql('SELECT * FROM SubmiteData',
         [],
         function(tx, results)
         { 
           for (var i=0; i<results.rows.length; i++) 
           {   
               var row=results.rows.item(i);
              // alert("Id: " + row['UserId']);
              var stringout = "LocId: " + row['LocId'] + "\n"; 
               alert(stringout); 
           } 
         },                
         globalError
        );
    });
   };

  $(function()
    {
     $('#show').click(read);
  });
 **html**

  <input id="show" type="button" value="Show">

 **js**

 function globalError(tx, error)
   {
     alert("Error: " + error.message);
   }

 var db = window.openDatabase('TabOrder', '', 'Bar Tab Orders', 2500000);
 db.transaction(function(tx) {
 tx.executeSql('DROP TABLE IF EXISTS SubmiteData;', null, null, globalError);
 tx.executeSql('CREATE TABLE IF NOT EXISTS SubmiteData (SubmiteDataId integer 
 primary  key, UserId text, AuthNo number, LocId number,ProdId number, 
 CardId number, OrgLat text, OrgLng text, OrgTime text)', 
          null, 
          function()
          {
            SubmiteData("USER1",12345678,23434, 21212, 220232,
            "9", "45", "23/06/2014");

          },
          globalError);
     });

    function SubmiteData(UserId, AuthNo, LocId,ProdId, CardId, OrgLat, OrgLng, OrgTime){
    db.transaction(function(tx){
    tx.executeSql('INSERT INTO SubmiteData(UserId, AuthNo, LocId, ProdId, CardId, 
    OrgLat, OrgLng, OrgTime) VALUES (?,?,?,?,?,?,?,?)', [UserId, AuthNo, LocId,
    ProdId, CardId, OrgLat, OrgLng, OrgTime], 
            null,
            globalError
           );
     });
  }


   function read(UserId, AuthNo, LocId,ProdId, CardId, OrgLat, OrgLng, OrgTime){

   db.transaction(function(tx) {
   tx.executeSql('SELECT * FROM SubmiteData',
         [],
         function(tx, results)
         { 
           for (var i=0; i<results.rows.length; i++) 
           {   
               var row=results.rows.item(i);
              // alert("Id: " + row['UserId']);
              var stringout = "LocId: " + row['LocId'] + "\n"; 
               alert(stringout); 
           } 
         },                
         globalError
        );
    });
   };

  $(function()
    {
     $('#show').click(read);
  });
终止放荡 2024-10-31 08:36:31

这是使用javascript连接数据库的方法

db = openDatabase("bprueba","1.0","Prueba_db",5*1023*1024);

SQL语句错误回调参考

this is the method to connect to a db using javascript

db = openDatabase("bprueba","1.0","Prueba_db",5*1023*1024);

SQL Statement Error Callback Reference

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文