i'我正在开发一个phonegap应用程序,但它无法连接数据库.我附加了以下程序
i'm developing a phonegap application but it cannot connect the database i attached the following program?
**我正在开发一个phonegap应用程序,但它无法连接我附加的数据库?我的代码如下:**
function onDeviceReady() {
var mobno = document.getElementById("mobno").value;
var cust = document.getElementById("cust").value;
db = window.openDatabase("RegistrationDB", "1.0", "Registration", 200000);
if (dbCreated)
else
db.transaction(populateDB, transaction_error, populateDB_success);
}
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS Registration');
var sql = "CREATE TABLE IF NOT EXISTS Registration ( "
+ "mobno INTEGER(50), " + "custname VARCHAR(50))";
tx.executeSql(sql);
var mobno = document.getElementById("mobno").value;
var cust = document.getElementById("cust").value;
tx.executeSql("INSERT INTO Registration (mobno,custname) VALUES ('"+ mobno +"','"+ cust +"')");
}
function transaction_error(tx, error) {
alert("Database Error: " + error);
}
function populateDB_success() {
dbCreated = true;
// where you want to move
alert("Successfully inserted");
window.location="file:///android_asset/www/login.html";
}
如果你想使用Cordova SqlLite插件,你必须安装它:
cordova plugin add https://github.com/brodysoft/Cordova-SQLitePlugin
接下来,您可以在设备中创建数据库:
function onDeviceReady() {
var db = window.sqlitePlugin.openDatabase("Database", "1.0", "Demo", -1);
db.transaction(function(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');
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");
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);
});
});
}
相关文章:
- Rails-JQueryUIAutcomplete和AJAX不工作,可以't连接到数据库
- 在cordova android应用程序中连接数据库
- 连接SQlite数据库
- 如何从Meteor内部获取当前连接的MongoDB数据库的URL
- 尝试使用javascript连接访问数据库
- 使用 JavaScript 连接数据库服务器的方法有多少种
- i'我正在开发一个phonegap应用程序,但它无法连接数据库.我附加了以下程序
- 在安装流星postgres之前有什么步骤吗?我无法连接数据库
- 猫鼬连接数据库时出错
- 在连接数据库时最好使用include或include_once
- 如何使用Ajax连接数据库(jsp)检查输入验证
- 使用JavaScript连接数据库
- 如何为这个angular登录代码连接数据库
- HTML5+javascript,如何连接数据库,如oracle,msql
- 我们可以用javascript连接数据库进行功能测试吗?
- Postgres + Node,将开发环境迁移到Windows,并且在连接数据库时遇到认证问题
- php,使用mysql_connect()连接数据库的问题,如何
- 使用Angular.js连接数据库和模型
- 使用Javascript API连接数据库
- 当我试图连接数据库时,是否有任何问题?