插入PhoneGap的数据库表中的数据?数据库、数据、PhoneGap

2023-09-06 13:26:38 作者:自私的世界、自私的人

在我的应用程序,我想插入到表中的值。我在创建的DATABSE中的 onDeviceReady()方式的 index.html的文件。

In my application, i want to insert the value in the table. i have created the databse in onDeviceReady() method in the index.html file.

     <!DOCTYPE html>
<!-- Auto Generated with Sencha Architect -->
<!-- Modifications to this file will be overwritten. -->
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Teritree</title>
<script type="text/javascript" id="phonegap" src=
"cordova-2.0.0.js">
</script>

<script type="text/javascript" src="barcodescanner.js">
</script>

<script src="sencha-touch-all.js" type="text/javascript">
</script>

<link rel="stylesheet" type="text/css" href="app.css">
<script type="text/javascript" src="app/Ext.ux.touch.Rating.js">
</script>

<script type="text/javascript" src="app/app.js">
</script>

<script type="text/javascript">
        Ext.Loader.setConfig({ disableCaching: false });
        Ext.Ajax.setDisableCaching(false);    

</script>

<script type="text/javascript" charset="utf-8">

    var pictureSource;   // picture source
    var destinationType; // sets the format of returned value 
    var mydb;

    // Wait for PhoneGap to connect with the device
    function onLoad() {
        document.addEventListener("deviceready",onDeviceReady,false);
    }

    // PhoneGap is ready to be used!

    function onDeviceReady() {
        console.log("it is in ondevice ready method..");
        mydb = window.openDatabase("teritreeDb", "1.0", "TestDB", 10000);
        console.log("it is in ondevice ready method..1");
        mydb.transaction(populateDB, errorCB, successCB);
        console.log("it is in ondevice ready method..2");
   }

   function populateDB(tx) {
   console.log("it is in populateDB----------1");
     tx.executeSql('DROP TABLE IF EXISTS DEMO', function () {
         tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)', function () {
             console.log("Table created");
         });
     });

      // Transaction error callback
    //
    function errorCB(tx, err) {
        alert("Error processing SQL: "+err);
    }

    // Transaction success callback
    //
    function successCB() {
        alert("success!");
    }
}

</script>

<script type="text/javascript">
        if (!Ext.browser.is.WebKit) {
            alert("The current browser is unsupported.\n\nSupported browsers:\n" +
                "Google Chrome\n" +
                "Apple Safari\n" +
                "Mobile Safari (iOS)\n" +
                "Android Browser\n" +
                "BlackBerry Browser"
            );
        }

</script>
</head>
<body>
</body>
</html>

现在我已经在注册画面,我有提交按钮一次注册的屏幕和那里。所以,如果我点击提交按钮,所有的细节应该存储在数据库是指在DEMO table..So在控制器中,我写的按钮时,

Now i have one signup screen and there in the signup screen i have submit button. So if i click the submit button, all the details should store in the database means in the DEMO table..So in the controller, i am writing the button event,

     onSubmitButtonTap : function(button, e, options) {

        mydb = window.openDatabase("appDb", "1.0", "Test DB", 1000000);
        mydb.transaction(storeCustomerDetails, error, success);


    function storeCustomerDetails(tx)
    {
        tx.executeSql('insert into DEMO (id,data) values("1","Hello")');
        tx.executeSql('insert into DEMO (id,data) values("2","Hello World")');
    }

    function error(){
        alert("data is not inserted");
    }
    function success(){
        alert("data is succesfully inserted");
    }
},

但它给我的警告,数据未插入。 我跟着链接: PhoneGap的数据库链接

but it is giving me the alert, data is not inserted. I followed the link: Phonegap DB Link

请帮助..

推荐答案

使用科尔多瓦2.0.0与您的问题将得到解决。你就可以看到你在文件浏览器中创建的数据库。不要让我知道,如果它可以帮助你。

Use Cordova 2.0.0 and your issue will be solved.. You will be able to see the database you created in the file explorer. Do let me know if it helps you.