1

I am using phonegap and sqlite to develop cross-platform mobile app for android,ios,blackberry.For reference i am using http://docs.phonegap.com/en/1.0.0/phonegap_storage_storage.md.html. My index.html is below

1.i have got phonegap.jar in lib

2.got phonegap.js in assests/wwww

3.got sqlite browser and sql shell downloaded in my hardisk

4.got jquery.min.js

I would like to know how to give the location of my sqlite from index.html so that it can make a connection with it. If I just pass in phonegap.js it is not making connection to sqlite.

<head>
 <title>Contact Example</title>
   <script type="text/javascript" charset="utf-8" src="js/phonegap-1.4.0.js">    </script>      
        <script type="text/javascript" src="js/jquery.min.js"/></script>
        <script type="text/javascript" src="js/jquery.mobile-1.0rc2.min.js"></script>
       <script type="text/javascript" charset="utf-8">
     function onLoad(){
       document.addEventListener("deviceready", onDeviceReady, true);
    var db = window.openDatabase("Dummy_DB", "3.0", "Just a Dummy DB",200000); 
            alert("db="+db); //not printing
 }
 function onDeviceReady(){
      navigator.notification.alert("doo");//only printing this


 }

 <body onload="c()">
  <h1>n Example</h1>
  <p>Database</p>
</body>
saum22
  • 884
  • 12
  • 28

1 Answers1

2

There are couple of possible problems:

  • When you call openDatabase the document has loaded, but phonegap has not. The problem is that you call the method c() onBodyLoad not onDeviceReady as advised in the phonegap tutorial. See here.
  • Please also check you add the javascript accordingly. A very good way to check is to add the eventListener for deviceready. If it gets fired the javascript is loaded ok.
Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
  • for accesing sqlite databasedo i just need to include phonegap.js and phonegap.jar or do i need to tell my application where sqlite is which i have downloaded – saum22 Feb 07 '12 at 10:03
  • Phone gap has a default where the database is - it has its own database to manage (it creates it and maintains it). If you want to connect to existing database you might find this thread useful: http://groups.google.com/group/phonegap/browse_thread/thread/5e57a728dc66a2a1?pli=1. – Boris Strandjev Feb 07 '12 at 10:14
  • so to create a new db in sqlite phonegap i just need to use window.openDatabase.? also I added listener and device ready but it is giving Uncaught Error: INVALID_STATE_ERR: DOM Exception 11 at file:///android_asset/www/index.html:13 ..in log... – saum22 Feb 07 '12 at 11:04
  • If this is the updated code then still you have the same problem - `addEventListener` is done outside the `onLoad` body see the example in the documentation I pointed you to. The database is created yes: see here: http://docs.phonegap.com/en/1.0.0/phonegap_storage_storage.md.html#openDatabase 'This method will create a new SQL Lite Database and return a Database object. Use the Database Object to manipulate the data.' – Boris Strandjev Feb 07 '12 at 11:38
  • i have connected my existing database with my html file but if i will upload it to phonegap build.It will generate new database at run time(what i think).Can you tell me is it possible to add my database with html file and upload it to phonegap so that it can generate app for different platform linked to my database. – saum22 Feb 09 '12 at 10:02
  • I am not aware of such a way, but never sought for it explicitly. If you want platform-by-platform solution refer to the link from my first comment. – Boris Strandjev Feb 09 '12 at 15:43