0

我对 PhoneGap 还很陌生,并且正在构建连接到现有 SQLite 数据库的问题。下面是我的代码。通过日志条目和警报,我注意到 javascript 正在运行,但很明显我的 openDatabase 调用没有完全正确设置。我得到的错误是“错误:无法准备语句(1没有这样的表:人)(代码5)”

if(openDatabase){
                 db = openDatabase('popfon.sqlite'
                                    , '1.0'
                                    , 'Database Description'
                                    , 200000;
    }
                  //Alert the user to upgrade their browser
                  else {
                  alert('Databases not supported. Please get a proper browser');
                  }
  $JQuery("#theButton").click(function(){getData()});

function getData(){
    //Create an empty results string
    var strResults = '';
    //Open a new transaction
    db.transaction(function(tx){
                   //Select a wildcard from the database
                   var theQuery = "SELECT * FROM person where OfficialName like '%law%'"
                   alert(theQuery);
                   tx.executeSql(theQuery
                                 ,[]
                                 //Callback function with transaction and
                                 //results objects
                                 ,function(tx, results){
                                 //Count the results rows
                                 var rowsCount = results.rows.length;
                               //  alert("rowsCount: "+rowsCount);
                                 //Loop the rows
                                 for (var i = 0; i < rowsCount; i++){
                                 //Build a results string, notice the
                                 //column names are called
                                 strResults += 'Your Name is'
                                 + results.rows.item(i).personName
                                 + ' Your ID is '
                                 + results.rows.item(i).personId
                                 + ' Your age is '
                                 + results.rows.item(i).personAge
                                 + ' Your favourite colour is '
                                 + results.rows.item(i).personColour
                                 + '';
                                 }
                                 //Fill the results DIV
                                 $('.results').html(strResults);
                                 }
                                 ,errorHandler);
                   });
}
4

0 回答 0