嗨,我是手机上的新手..我现在尝试使用带数据库的phonegap,我能够在模拟器/获取记录中显示记录..但是当我尝试在build.phonegap.com中构建应用程序时。 apk当我安装应用程序并运行在我的Android没有记录显示..我的问题是我如何构建我的应用程序,包括数据库?我有.db已经在哪里放置它或我需要添加一些脚本?希望你明白我的意思,对不起我的英语..
这是代码:
<!DOCTYPE html>
<html>
<head>
<title>Storage Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.4.0.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
}
function clickFunc(){
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(selectData);
}
function selectData(tx){
tx.executeSql("SELECT * FROM test",[],resultSuccess,resultError);
}
function resultError(error){
alert("Error: "+error);
}
function resultSuccess(tx, response){
var div = document.getElementById('display');
var tmp = "<table><tr><th>ID</th><th>DATA</th></tr>";
for(var i = 0;i<response.rows.length;i++){
tmp += "<tr><td>" + response.rows.item(i).id + "</td><td>" + response.rows.item(i).data + "</td></tr>";
div.innerHTML = tmp;
}
}
</script>
</head>
<body>
<input type="button" value="FITCH" id="btnSelect" onclick="clickFunc();"/>
<div id="display">
</div>
答案 0 :(得分:1)
您的仅创建数据库,但您不创建任何表,也无需插入任何表。这样你的apk就不会产生你的例外结果。
所以你会试试这段代码
<!DOCTYPE html>
<html>
<head>
<title>Storage Example</title>
<script type="text/javascript" charset="utf-8" src="cordova-2.4.0.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
//
function onDeviceReady() {
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
}
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS DEMO');
tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}
function clickFunc(){
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(selectData);
}
function selectData(tx){
tx.executeSql("SELECT * FROM test",[],resultSuccess,resultError);
}
function resultError(error){
alert("Error: "+error);
}
function resultSuccess(tx, response){
var div = document.getElementById('display');
var tmp = "<table><tr><th>ID</th><th>DATA</th></tr>";
for(var i = 0;i<response.rows.length;i++){
tmp += "<tr><td>" + response.rows.item(i).id + "</td><td>" + response.rows.item(i).data + "</td></tr>";
div.innerHTML = tmp;
}
}
</script>
</head>
<body>
<input type="button" value="FITCH" id="btnSelect" onclick="clickFunc();"/>
<div id="display">
</div>
如果您需要更多详细信息,请参阅以下链接:http://docs.phonegap.com/en/2.7.0/cordova_storage_storage.md.html#Storage