<! Doctype html> <html> <head> <meta charset = utf-8> <title> Exemplo de banco de dados </title> <script type = text/javascript charset = utf-8 src = cordova.js> </sCript> <script type = text/javascript charset = utf-8> document.addeventListener (deviceReady, OnDevicEready, false); function OnDeviceady () {var db = window.opendatabase (teste, 1.0, teste, 200000); db.Transaction (PowuledB, Errordb, SUCCESTDB); } // 初始化数据库数据 função povoulb (tx) {tx.executesql ('tabela de soltar se existe test1'); tx.executesql ('Criar tabela se não existe test1 (id exclusivo, nome)'); tx.executesql ('inserir no teste1 (id, nome) valores (1, tony)'); tx.executesql ('inserir no teste1 (id, nome) valores (2, fatura)'); tx.executesql ('inserir no teste1 (id, nome) valores (3, tony)'); } // 查询方法 função querydb (tx) {tx.executesql ('selecione * de test1', [], consulsão, errordb); } // 查询成功回调 Função QuerySuccess (tx, resultados) {var len = results.rows.length; var status = document.getElementById (status); var string = linhas:+len+<r />; for (var i = 0; i <len; i ++) {string+= results.rows.item (i) .name+<r />; } status.innerhtml = string; } // 执行初始化数据成功后的回调 função succcessDB () {var db = window.opendatabase (teste, 1.0, teste, 200000); db.Transaction (Querydb, errordb); } // 失败回调 função errordb (err) {alert ('Processamento de erro sql:'+err.code); } </script> </ading> <body> <h1> nomes </h1> <div id = 'status'> </div> </body> </html>以上这篇使用 PhoneGap 操作数据库的实现方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持 VEVB 武林网。