Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store data in sqlite database using jQuery-mobile dreamviewer cc with phonegap in android?

Am new in developing android app in Dreamweaver CC with Phone-gap. I designed simple form in that having 4 fields I need to store this fields in sqlite database? In eclipse import sqlite database and open database connection and then create table and store data. This is working fine, I need to do same here in Dreamweaver CC?

import android.database.sqlite.SQLiteDatabase;
SQLiteDatabase db;
db = this.openOrCreateDatabase("QAOD", MODE_PRIVATE, null);
db.execSQL("INSERT INTO TableName(Id) VALUES(18)");

This format code is working fine in eclipse android but I need use this code and store data in sqlite in Dreamweaver CC with Phone-gap. Help me or suggest me to store data.

like image 763
Srihari Avatar asked Jan 10 '15 13:01

Srihari


1 Answers

You mentioned you are using Phonegap. These are the steps to create and add records to sqlite database in Android

First: Add Plugin

cordova plugin add https://github.com/brodysoft/Cordova-SQLitePlugin

Second: Open Database

document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
  var db = window.sqlitePlugin.openDatabase({name: "my.db"});
}

Third: Use it (Create, Update or Delete)

db.transaction(function(tx) {
    tx.executeSql('DROP TABLE IF EXISTS test_table');
    tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)');

    // demonstrate PRAGMA:
    db.executeSql("pragma table_info (test_table);", [], function(res) {
      console.log("PRAGMA res: " + JSON.stringify(res));
    });

You can read more here...

like image 143
Murtaza Khursheed Hussain Avatar answered Sep 29 '22 10:09

Murtaza Khursheed Hussain