【问题标题】:creating database in sqlite with cordova使用cordova在sqlite中创建数据库
【发布时间】:2014-12-29 05:24:50
【问题描述】:

这是我的 index.html,我不知道问题出在哪里,但此代码不会为我创建数据库,请提供任何帮助或 remarque。

<script type="text/javascript" charset="utf-8">
        document.addEventListener("deviceready", onDeviceReady, false);
        function onDeviceReady() {
                var db = window.openDatabase("test", "2.0", "Test DB", 1000000);    
                alert(window.openDatabase("test", "1.0", "Test DB", 1000000) +' kolll')
                db.transaction(populateDB, errorCB, successCB); 
                }

        // create table
        function populateDB(tx) {
         tx.executeSql('DROP TABLE IF EXISTS test_table');
         tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (ROLLING INT, firstname text, lastname text, numphone text)');
         tx.executeSql("INSERT INTO test_table VALUES('adam', 'smith', '887884')");
         tx.executeSql("INSERT INTO test_table VALUES('david', 'ooo', '15588')");
        }
        function errorCB(err) {
                  console.log("Error processing SQL: " + err.code);

        alert('DATABASE NOT CREATED ');
        }
        // Success error callback

        function successCB() {
                    alert('DATABASE CREATED ');

        } 
</script>

thank you

【问题讨论】:

    标签: javascript android html sqlite cordova


    【解决方案1】:

    您使用不同的版本(2.0 和 1.0)创建了两次数据库。

    1.var db = window.openDatabase("test", "2.0", "Test DB", 1000000);
    
    2.alert(window.openDatabase("test", "1.0", "Test DB", 1000000) +' kolll')
    

    您需要更改onDeviceReady() 中的警报调用。例如

    function onDeviceReady() {
        alert('Calling onDeviceReady');
    
        var db = window.openDatabase("test", "2.0", "Test DB", 1000000);    
        alert( 'window.openDatabase called' + ' kolll');
    
        db.transaction(populateDB, errorCB, successCB); 
    
    }
    

    上述更改有望创建数据库和表。

    【讨论】:

      猜你喜欢
      • 2019-01-28
      • 2018-03-17
      • 1970-01-01
      • 1970-01-01
      • 2018-09-09
      • 2011-10-07
      • 2023-04-03
      • 2013-02-03
      • 2019-01-14
      相关资源
      最近更新 更多