Android 使用Eclipse在计算机硬盘Phonegap上保存/检索Sqlite数据库
类似的问题已经问过了,但我在磁盘上找不到数据库Android 使用Eclipse在计算机硬盘Phonegap上保存/检索Sqlite数据库,android,eclipse,sqlite,cordova,Android,Eclipse,Sqlite,Cordova,类似的问题已经问过了,但我在磁盘上找不到数据库 DDMS->data-> again click data-> your package name->databases->db 我正在使用phonegap2.7.0构建一个简单的Android移动应用程序 我使用Sqlite数据库来存储数据。它工作得很好。它存储数据、插入数据并获取数据。但是当我需要在硬盘上推送数据库时,我无法在app\u database文件夹中看到数据库 为了将数据库从eclipse检索到计算
DDMS->data-> again click data-> your package name->databases->db
我正在使用phonegap2.7.0构建一个简单的Android移动应用程序
我使用Sqlite数据库来存储数据。它工作得很好。它存储数据、插入数据并获取数据。但是当我需要在硬盘上推送数据库时,我无法在app\u database文件夹中看到数据库
为了将数据库从eclipse检索到计算机硬盘,我使用了SQLite数据库浏览器2.0 b1
下面是我用来从eclipse中查看数据库的步骤
DDMS=>File Explorer=>data=>data=>=>AppU数据库
文件夹
所需的最低SDK:API 8:Android 2.2(Froyo)目标SDK:API 16:
Android 4.1(果冻豆)使用API 17编译Android 4.2(果冻豆)
PhongGap V:2.7.0;Android V:4.2 Eclipse版本:4.3
我使用下面的代码设置数据,从sqlite数据库获取数据
创建数据库和表
document.addEventListener("deviceready", OnDeviceReady, false)
function OnDeviceReady() {
alert("PhoneGap is ready");
}
function onCreate() {
try {
var mytx = window.openDatabase("Contact", "1.0", "Contact", 1000000);
mytx.transaction(funCreateData, funsuccess, funerror)
} catch (e) {
console.error(e.message);
}
}
function funCreateData(tx) {
try {
tx.executeSql('CREATE TABLE IF NOT EXISTS ContactList (id unique, name varchar)');
alert("created");
} catch (ex) {
alert(ex.message);
}
}
function funsuccess() {
alert("Debug on Success");
}
将数据插入Sqlite数据库
function onInsert() {
var mytx = window.openDatabase("Contact", "1.0", "Contact", 1000000);
mytx.transaction(funSetData, funSetsuccess, funerror)
}
function funSetData(tx) {
tx.executeSql('INSERT INTO ContactList (id, name) VALUES (1, "XYZ")');
}
function funSetsuccess() {
alert("Success");
}
从Sqlite数据库获取数据
function onSelect() {
var mytx = window.openDatabase("Contact", "1.0", "Contact", 1000000);
mytx.transaction(funGetData, funGetsuccess, funerror)
}
function funGetsuccess() {
alert("Success Select");
}
function funGetData(tx) {
tx.executeSql("select * from ContactList", [], successQ, funerror);
}
function successQ(tx, result) {
var len = result.rows.length;
alert(len);
var fname = result.rows.item(1).name;
alert(fname);
}
function funerror(err) {
alert("Error" + err.message);
}
PS:我应该问其他类似的问题吗