0

I need some database on my phonegap android application. I read about WebSQL and tried it, and I don't know if it stays after I close the app or it must be made every time i open the app. I need to keep data when app closes so i can use it when i open it again. What database should I use?

P.S. If u have some tutorial it would be nice. Thanks

JaSamSale
  • 169
  • 1
  • 2
  • 11
  • 1
    use sqlite [1]: http://stackoverflow.com/questions/6647474/how-to-implement-a-sqlite-database-in-phonegap –  Mar 28 '14 at 19:40

3 Answers3

2

The best option to store data in database for an Android Application using PhoneGap must be SQLite:

Android Storage Options

but you can use too WebSQL: SQLite database on PhoneGap

See this question suggested by sajad:

How to implement an SQLite database in Phonegap?

and a Tutorial: Create Android App with SQLite using Phonegap

Community
  • 1
  • 1
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
0

Follow this tutorial to learn how to use/create SQLite database in phonegrap (from official doc).

var db = window.openDatabase("test", "1.0", "Test DB", 1000000);

This method will create a new SQL Lite Database and return a Database object. Use the Database Object to manipulate the data.

Syntax + Tutorial:

window.openDatabase(name, version, display_name, size);

Example from the page:

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")');
}

function errorCB(err) {
    alert("Error processing SQL: "+err.code);
}

function successCB() {
    alert("success!");
}

var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(populateDB, errorCB, successCB);

I found this tutorial too.

Marco Acierno
  • 14,682
  • 8
  • 43
  • 53
0

To view the data stored in the database, follow these steps:

  1. Click on Windows > Open Perspective > DDMS. Go to File Explorer.

  2. Then /data/data/package_name/databases.But here we cannot see the tables and table data.

  3. For viewing the table details Eclipse has a plugin. Download it from http://androidcode-sqlite.blogspot.in/2013/04/sqlitemanager-plugin-for-eclipse-android.html.

  4. Now put the jar in the folder eclipse/dropins/.

  5. Click on Java Build Path > Libraries > Add External JARs > Choose Your Path to the SQLite JAR File! Add it.

  6. Restart the eclipse and now you can see the SQLite Manager plugin on the top right of the File Explorer window.

  7. Click on (database name), then click on “open file in SQLite Manager...”.

Here, click on “Questoid SQLite Manager” tab and you can see your table in “Database Structure” tab. Then, click on “Browse Data” tab to view your table data.

Anjy786
  • 145
  • 8