<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
var db;
//function will be called when device ready
function onDeviceReady() {
db = window.openDatabase("Dummy_DB", "1.0", "Just a Dummy DB", 200000); //will create database Dummy_DB or open it
db.transaction(populateDB, errorCB, successCB);
}
//create table and insert some record
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS SoccerPlayer');
tx.executeSql('CREATE TABLE IF NOT EXISTS SoccerPlayer (id integer primary key, Name text, Club text)');
tx.executeSql('INSERT INTO SoccerPlayer(Name,Club) VALUES ("Alexandre Pato", "AC Milan")');
tx.executeSql('INSERT INTO SoccerPlayer(Name,Club) VALUES ("Van Persie", "Arsenal")');
}
//function will be called when an error occurred
function errorCB(err) {
alert("Error processing SQL: " + err.code);
}
//function will be called when process succeed
function successCB() {
alert("success!");
db.transaction(queryDB, errorCB, successCB);
}
function queryDB(tx) {
tx.executeSql('SELECT Name,Club FROM SoccerPlayer', [], querySuccess);
}
function querySuccess(tx, result) {
$('#SoccerPlayerList').empty();
$.each(result.rows, function (index) {
var row = result.rows.item(index);
$('#SoccerPlayerList').append('<li><a href="#"><h3 class="ui-li-heading">' + row['Name'] + '</h3><p class="ui-li-desc">Club ' + row['Club'] + '</p></a></li>');
});
$('#SoccerPlayerList').listview();
}
</script>
我使用phonegap创建了存储和反向数据库的示例,但是首先警告成功,然后在抛出错误0之后。请帮助我,我是phonegap的新手..
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
var db;
//function will be called when device ready
function onDeviceReady() {
db = window.openDatabase("Dummy_DB", "1.0", "Just a Dummy DB", 200000); //will create database Dummy_DB or open it
db.transaction(populateDB, errorCB, successCB);
}
//create table and insert some record
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS SoccerPlayer');
tx.executeSql('CREATE TABLE IF NOT EXISTS SoccerPlayer (id integer primary key, Name text, Club text)');
tx.executeSql('INSERT INTO SoccerPlayer(Name,Club) VALUES ("Alexandre Pato", "AC Milan")');
tx.executeSql('INSERT INTO SoccerPlayer(Name,Club) VALUES ("Van Persie", "Arsenal")');
}
//function will be called when an error occurred
function errorCB(err) {
alert("Error processing SQL: " + err.code);
}
//function will be called when process succeed
function successCB() {
alert("success!");
db.transaction(queryDB, errorCB, successCB);
}
function queryDB(tx) {
tx.executeSql('SELECT Name,Club FROM SoccerPlayer', [], querySuccess);
}
function querySuccess(tx, result) {
$('#SoccerPlayerList').empty();
$.each(result.rows, function (index) {
var row = result.rows.item(index);
$('#SoccerPlayerList').append('<li><a href="#"><h3 class="ui-li-heading">' + row['Name'] + '</h3><p class="ui-li-desc">Club ' + row['Club'] + '</p></a></li>');
});
$('#SoccerPlayerList').listview();
}
</script>
答案 0 :(得分:0)
这可能对您有所帮助
function queryDB(tx){
tx.executeSql('SELECT Name,Club FROM SoccerPlayer', [], querySuccess,errorCB);
}