我正在使用以下代碼從數據庫獲取數據並在listview中顯示內容。但我不想在每次加載應用程序時創建數據庫...我只想創建一次...但是,每當應用程序關閉時,數據庫都會被刪除。我希望它保持原樣,以便下次添加數據而不創建它。Android Phonegap數據庫
var arr = new Array();
var a;
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(populateDB, errorCB, successCBc);
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS CUSTOMER');
tx.executeSql('CREATE TABLE IF NOT EXISTS CUSTOMER (phno unique, fname, mname, lname, address, email)');
tx.executeSql('INSERT INTO CUSTOMER (phno, fname, mname, lname, address, email) VALUES (16, "shank","p","ram","addresssss","emailaddress")');
};
function queryDB(tx) {
tx.executeSql('SELECT * FROM CUSTOMER', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
var len = results.rows.length;
for (var i=0; i<len; i++){
$('#home').append('<li><a href="#artists">'+results.rows.item(i).phno+'<br>'+results.rows.item(i).fname+'</a></li>').listview("refresh");
}
};
function errorCB(err) {
console.log("Error processing SQL: "+err.code);
}
function successCBc() {
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(queryDB, errorCB);
};
嘗試vth dat也... bt nt wrkng – 2012-03-06 09:46:16
顯示我的所有記錄。讓我把整個代碼在回答 – dhaval 2012-03-06 11:19:04
檢查這個小提琴[http://jsfiddle.net/dhavaln/DFUNK/](http://jsfiddle.net/dhavaln/DFUNK/) – dhaval 2012-03-06 11:22:49