无法将值插入sqlite数据库

时间:2014-12-01 05:15:07

标签: jquery database html5 sqlite cordova

我正在尝试将值插入sqlite数据库,但我无法获得成功。我正在尝试将此值添加到cordova phonegap应用程序中。因为这意味着在设备中作为手机应用程序运行,所以我在功能中设置警报以检查功能的流程,但不幸的是我只获得一个进入功能的警报。以后的警报,我无法收到。

这是代码。

function InsertMobileData(){
        myDB.transaction(function(transaction) {
            // Define insert query
            alert("In")
            var executeQuery = "INSERT INTO " +
                                "Mobile_Table" + 
                                "(device_PhoneNumber) "+
                                "VALUES(?)";
            Helper.log(executeQuery); 
            alert(callingNo);
            alert(executeQuery);
            transaction.executeSql(executeQuery, ['"+callingNo+"']
                , function(tx, result) {   // On success
                 alert("Mobile Number Inserted Successfully");
                },
                function(error){     // On error                               
                     alert("Error while inserting data");
                });
        });
}

请帮我纠正代码。感谢。

3 个答案:

答案 0 :(得分:1)

首先是代码中的语法错误“transaction.executeSql(executeQuery,['”+ callingNo +“']” 您可以尝试使用此代码进行工作......

function InsertMobileData(){
    myDB.transaction(function(transaction) {           
       var executeQuery = "INSERT INTO Mobile_Table (device_PhoneNumber) VALUES('"+callingNo+"')";
       transaction.executeSql(executeQuery, []
            , function(tx, result) {   // On success
             alert("Mobile Number Inserted Successfully");
            },
            function(error){     // On error                               
                 alert("Error while inserting data");
            });
    });      
}

答案 1 :(得分:0)

尝试在"Mobile_Table" +之后添加空格,使其读取

var executeQuery =
  "INSERT INTO " +
  "Mobile_Table " + 
  "(device_PhoneNumber) "+
  "VALUES(?)";

答案 2 :(得分:0)

我认为sql没有问题,你可以使用insert into tablename(colname) values(theValue)

你有警报:

alert(callingNo);

但是我没有看到var callingNo。也许这里有一个错误。

相关问题