2014-11-04 111 views
1

錯誤代碼0 SQLite中與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>

我已創建例如商店,並使用PhoneGap的,但第一個警報更迭,然後拋出後誤差0 retrive數據庫。請幫助我,我在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

'Sqlite' - 錯誤代碼0 - >確定。 – 2014-11-04 05:35:15

+0

是的,先生的錯誤代碼0 – 2014-11-04 05:40:41

+0

我有同樣的問題,試圖找到任何答案! – 2015-03-28 01:01:15

回答

0

這可能會幫助你

功能queryDB(TX){

  tx.executeSql('SELECT Name,Club FROM SoccerPlayer', [], querySuccess,errorCB); 
     } 
相關問題