简体   繁体   中英

How to read database from SD card in PhoneGap

I am new to Phonegap. i want to read Database file from SDcard. i created one "demo" Database through SQLite Browser then i place it into SDcard. Now i want to read it from SDcard. I am using the following code but it is not working.

     function save_address(name) {

 var db;
 db = window.openDatabase("../../../mnt/sdcard/demo", "1.0", "demo", 200000);
 console.log("DataBaseObject::::::::::"+db);
 db.transaction(populateDB, errorCB, successCB);

  }

       function populateDB(tx) {

        tx.executeSql('INSERT INTO tbl_DEMO (id, name,  number)VALUES(1,"Firstrow",1)');
         tx.executeSql('INSERT INTO tbl_DEMO (id, name, number) VALUES (2, "Second row",2)');
    }

    // Query the database
   //
    function queryDB(tx) {
        tx.executeSql('SELECT * FROM tbl_DEMO', [], querySuccess, errorCB);
   }

       // Query the success callback
        //
       function querySuccess(tx, results) {
       var len = results.rows.length;
         console.log("DEMO table: " + len + " rows found.");
       for (var i=0; i<len; i++){
          console.log("Row = " + i + " ID = " + results.rows.item(i).id + " Data =  "  + results.rows.item(i).data);
        }
       }

     // Transaction error callback
      //
       function errorCB(err) {
        console.log("Error processing SQL: "+err.code);
        }

       // Transaction success callback
       //
      function successCB() {
      var db = window.openDatabase("../../../mnt/sdcard/demo", "1.0", "Cordova Demo",      200000);
     db.transaction(queryDB, errorCB);
   }

I'm investigating your same thing. Is it possible to load/create database in sdcard using phoneGap in Android?

Here they say to use a "../../../../" 4 upper level, not 3.

Good luck (to me too..)..!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM