gpt4 book ai didi

sqlite - Cordova Android SQLLIteplugin.open异常

转载 作者:行者123 更新时间:2023-12-03 17:58:12 25 4
gpt4 key购买 nike

我正在尝试为Android使用SQLLItePlugin,但无法正常工作。我将列出我的步骤:
1.我已经从phonegap安装了cordova pjhonegap。我正在使用Netbeans作为IDE开发移动应用程序Phonegap,html5,javascript,css3。
2.从https://github.com/brodysoft/Cordova-SQLitePlugin下载的插件。
3.在项目的js文件夹中添加了SQLitePlugin.js。
4.在plugin.properties中添加了com.brodysoft.sqlitePlugin.file = https://github.com/brodysoft/Cordova-SQLitePlugin.git
5.在设备上打开数据库

       var app = {
initialize: function () {
this.bindEvents();
},
bindEvents: function () {
document.addEventListener('deviceready', this.onDeviceReady, false);
},
onDeviceReady: function () {
app.receivedEvent('deviceready');
var db = window.sqlitePlugin.openDatabase('gdata.db');
console.log('ready');


db.transaction(function (tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');

// demonstrate PRAGMA:
db.executeSql("pragma table_info (test_table);", [], function (res) {
console.log("PRAGMA res: " + JSON.stringify(res));
});

tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function (tx, res) {
console.log("insertId: " + res.insertId + " -- probably 1");
console.log("rowsAffected: " + res.rowsAffected + " -- should be 1");

db.transaction(function (tx) {
tx.executeSql("select count(id) as cnt from test_table;", [], function (tx, res) {
console.log("res.rows.length: " + res.rows.length + " -- should be 1");
console.log("res.rows.item(0).cnt: " + res.rows.item(0).cnt + " -- should be 1");
});
});

}, function (e) {
console.log("ERROR: " + e.message);
});
});



},
// Update DOM on a Received Event
receivedEvent: function (id) {
var parentElement = document.getElementById(id);
console.log('Received Event: ' + id);
}
};
app.initialize();



直接在android devvice上运行构建。


它不断抛出错误


未捕获的TypeError:对象#没有方法'exec'
(13:52:13:450 |错误,javascript)
在SQLitePlugin.open(www / js / libs / SQLitePlugin.js:112:15)
在SQLitePlugin(www / js / libs / SQLitePlugin.js:54:10)
在(匿名函数)(www / js / libs / SQLitePlugin.js:425:14)
在(匿名函数)(www / js / libs / SQLitePlugin.js:30:20)
在createandpopulatedb(www / js / dborarray.js:30:30)
在onDeviceReady3(www / dborarray.html:96:33)
在onload(www / dborarray.html:16:155)的SQLitePlugin openargs:{“ name”:“ gdata enter code here .db”}(13:52:19:609)在
www / js / libs / SQLitePlugin.js:39


有人可以帮忙吗?

最佳答案

试试这个

window.sqlitePlugin.openDatabase({name: "gdata.db"});

代替这个
window.sqlitePlugin.openDatabase('gdata.db');

关于sqlite - Cordova Android SQLLIteplugin.open异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27799194/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com