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

北城余情 提交于 2019-12-12 10:39:23

问题


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.


回答1:


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...



来源:https://stackoverflow.com/questions/27876632/how-to-store-data-in-sqlite-database-using-jquery-mobile-dreamviewer-cc-with-pho

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!