【发布时间】:2015-03-04 03:38:17
【问题描述】:
我正在尝试使用适用于 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 设备上运行构建。
一直报错
Uncaught TypeError: Object # has no method '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
有人可以帮忙吗?
【问题讨论】:
-
点击此链接可能会有所帮助:stackoverflow.com/questions/27187826/…