1

I am trying to build a game in android most of the part of the game is written in HTML5 a sqlite database is also created for the same. I want to access the sqlite database created in HTML5 from java to add or remove values?

Any phonegap plugin for that?

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Nikhil Ranjan
  • 994
  • 12
  • 16

2 Answers2

3

please read this issue this may help u to get clear idea how to use sqlite data base in phonegap

here some information has been given regarding websqite database http://www.w3.org/TR/webdatabase/

http://diveintohtml5.info/storage.html

and for more information regarding this issue have a look at this query

SQLite database on PhoneGap

best of luck

Aamirkhan I.

Community
  • 1
  • 1
Aamirkhan
  • 5,746
  • 10
  • 47
  • 74
1
**Plugin name**
 cordova plugin add https://github.com/millerjames01/Cordova-SQLitePlugin.git

**html**
<input id="show" type="button" value="Show">

**js**

function globalError(tx, error)
   {
     alert("Error: " + error.message);
   }

var db = window.openDatabase('TabOrder', '', 'Bar Tab Orders', 2500000);
db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS SubmiteData;', null, null, globalError);
tx.executeSql('CREATE TABLE IF NOT EXISTS SubmiteData (SubmiteDataId integer 
primary  key, UserId text, AuthNo number, LocId number,ProdId number, 
CardId number, OrgLat text, OrgLng text, OrgTime text)', 
          null, 
          function()
          {
            SubmiteData("USER1",12345678,23434, 21212, 220232,
            "9", "45", "23/06/2014");

          },
          globalError);
 });

 function SubmiteData(UserId, AuthNo, LocId,ProdId, CardId, OrgLat, OrgLng, OrgTime){
 db.transaction(function(tx){
 tx.executeSql('INSERT INTO SubmiteData(UserId, AuthNo, LocId, ProdId, CardId, 
 OrgLat, OrgLng, OrgTime) VALUES (?,?,?,?,?,?,?,?)', [UserId, AuthNo, LocId,
 ProdId, CardId, OrgLat, OrgLng, OrgTime], 
            null,
            globalError
           );
 });
}


 function read(UserId, AuthNo, LocId,ProdId, CardId, OrgLat, OrgLng, OrgTime){

 db.transaction(function(tx) {
 tx.executeSql('SELECT * FROM SubmiteData',
         [],
         function(tx, results)
         { 
           for (var i=0; i<results.rows.length; i++) 
           {   
               var row=results.rows.item(i);
              // alert("Id: " + row['UserId']);
              var stringout = "LocId: " + row['LocId'] + "\n"; 
               alert(stringout); 
           } 
         },                
         globalError
        );
   });
 };

$(function()
{
    $('#show').click(read);
});
Narsingh Tomar
  • 487
  • 5
  • 15