12

I'm new to this, and I am trying to build an app to be deployed with PhoneGap, to both Android and iOS. I am wondering how to link to a database which will store timetable data.

My question is how to include the database so it can be packaged with PhoneGap.

I have looked at the PhoneGap docs, and they don't really make sense to me as to how to set up/create the database


Update: This website shows some info on local storage, but when i put it in, hangs on the loading image.

Any further ideas?

http://www.aquim.com/web-article-237.html

1
  • Did you find where we can see our data in db for android Commented Jul 17, 2014 at 11:28

3 Answers 3

13

Please refer below link for simple operation with Sq-lite.and also you can get basic idea of Storage API from above link.

Simple operation with Sq-lite : http://www.raymondcamden.com/index.cfm/2011/10/20/Example-of-PhoneGaps-Database-Support

Edited on 8th MAY 2013 and fixed 19th January 2016

Basic operation with DB :

<script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for Cordova to load
document.addEventListener("deviceready", onDeviceReady, false);

// Cordova is ready
function onDeviceReady() {
    var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
    db.transaction(populateDB, errorCB, successCB);
}

// Populate the database 
function populateDB(tx) {
    tx.executeSql('DROP TABLE IF EXISTS DEMO');
    tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)');
    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")');
    tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")');
}

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

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

refrence

You can check Data base in File explorer

In ADT bundle Window>>show view>> File Explorer

Sign up to request clarification or add additional context in comments.

8 Comments

I have tried, but when I built the application in PhoneGap, and deployed it to an Android device, none of the database worked, I have tried link as well as the ones above, with the same result. Any html/css works fine.
please refer Basic operation with DB.
I am now more comfortable with SQL, so it now looks like it will work, will implement it soon. Thanks
Is it possible to find where we can see our data in db for android
Page is not opening now please give other like
|
1

PhoneGap has a storage api that you should use instead of using HTML5 local storage directly. On both Android and iOS, it will use the native implementation.

see http://docs.phonegap.com/en/2.7.0/cordova_storage_storage.md.html#Storage

3 Comments

I have tried that, but as with the comment above, I get no database result.
Perhaps you could be more specific - please show your code and tell us exactly what the behavior / result is.
Is it deprecated in the latest version? I couldn't find similar documentation in the latest docs.phonegap.com/en/3.4.0/… . Instead, it suggests to use HTML 5 based storage
0

Careful because maxSize of database in Android Gingerbread 2.3.3 emulator must be 65535.

With this OS 200000 maxSize it could give an error.

200000 maxSize works for newer OS.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.