我如何在Android中创建/打开数据库? [英] how i create/open database in android?
本文介绍了我如何在Android中创建/打开数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的PhoneGap,正用X code此code,那么正常运行和,iPhone模拟器数据库展示 - > 5.0 - >应用程序 - >(应用程序名称) - >的Webkit - >数据库
但是,当我我们在Eclipse中,那么它不会造成ddms->数据 - >数据 - >数据库的任何数据库。
它是如何工作的正确。我建议
<!DOCTYPE HTML>
< HTML和GT;
< HEAD>
<标题>联系例< /标题> <脚本类型=文/ JavaScript的字符集=utf-8SRC =phonegap.js>< / SCRIPT>
<脚本类型=文/ JavaScript的字符集=utf-8> //等待的PhoneGap加载
//
document.addEventListener(deviceready,onDeviceReady,FALSE); // PhoneGap的准备
//
功能onDeviceReady(){
变种DB = window.openDatabase(数据库,1.0,PhoneGap的演示,200000);
db.transaction(populateDB,errorCB,successCB);
} //填充数据库
//
功能populateDB(TX){
tx.executeSql(DROP TABLE IF EXISTS DEMO');
tx.executeSql(CREATE TABLE IF NOT EXISTS DEMO(ID唯一,数据)');
tx.executeSql(INSERT INTO DEMO(ID,数据)VALUES(1,第一行)');
tx.executeSql(INSERT INTO DEMO(ID,数据)VALUES(2,第二排)');
} //交易错误回调
//
功能errorCB(德克萨斯州,ERR){
警报(错误处理SQL:+ ERR);
} //交易成功回调
//
功能successCB(){
警报(成功!);
} < / SCRIPT>
< /头>
<身体GT;
&所述; H1物实施例&下; / H1>
&所述p为H.;数据库与所述; / P>
< /身体GT;
< / HTML>
解决方案
DDMS没有访问/ data目录。看到这些解决方法这两个计算器讨论:
i am using PhoneGap,n using this code in xCode then run properly and database show in, iphone simulator-->5.0-->Applications--> (application name) --> Webkit --> Database
But when i us in Eclipse, then it not create any database in ddms->data->data->database. how it work proper. Suggest me
<!DOCTYPE html>
<html>
<head>
<title>Contact Example</title>
<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
var db = window.openDatabase("Database", "1.0", "PhoneGap 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(tx, err) {
alert("Error processing SQL: "+err);
}
// Transaction success callback
//
function successCB() {
alert("success!");
}
</script>
</head>
<body>
<h1>Example</h1>
<p>Database</p>
</body>
</html>
解决方案
DDMS does not have access to the /data directory. See these these two stackoverflow discussions for workarounds:
这篇关于我如何在Android中创建/打开数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文