惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Last Watchdog
The Last Watchdog
博客园_首页
Martin Fowler
Martin Fowler
S
SegmentFault 最新的问题
美团技术团队
小众软件
小众软件
V
V2EX
博客园 - Franky
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
Attack and Defense Labs
Attack and Defense Labs
S
Security Affairs
Simon Willison's Weblog
Simon Willison's Weblog
I
Intezer
T
The Exploit Database - CXSecurity.com
有赞技术团队
有赞技术团队
S
Schneier on Security
人人都是产品经理
人人都是产品经理
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
K
Kaspersky official blog
PCI Perspectives
PCI Perspectives
AI
AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
罗磊的独立博客
O
OpenAI News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Register - Security
The Register - Security
V
Vulnerabilities – Threatpost
GbyAI
GbyAI
博客园 - 【当耐特】
C
Cisco Blogs
大猫的无限游戏
大猫的无限游戏
Help Net Security
Help Net Security
Google DeepMind News
Google DeepMind News
S
Securelist
Application and Cybersecurity Blog
Application and Cybersecurity Blog
P
Proofpoint News Feed
博客园 - 三生石上(FineUI控件)
雷峰网
雷峰网
L
LangChain Blog
SecWiki News
SecWiki News
博客园 - 叶小钗
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
V2EX - 技术
V2EX - 技术
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
J
Java Code Geeks
L
LINUX DO - 热门话题
Cisco Talos Blog
Cisco Talos Blog

博客园 - chinachen

查看DLL 版本 平台 x86 x64 MS SQL2008 数据库备份(收集) C# 接口 索引 属性 实质及应用 (收集) get set 用法总结 (收集) MVC 资料收集(一) windows运行命令大全 Html:meta标签的奥妙 (收集) - chinachen - 博客园 ASP.NET抓取页面并分析页面数据的研究与探讨。 C#中indexof和substring函数用法 (收集) - chinachen - 博客园 BlogEngine 深入研究(一) 开篇 ASP.NET实现回调服务器方法 (收集) 统一过程,敏捷过程,微软过程(收集) HTTP服务器状态代码定义(Status Code Definitions)(收集) Lambda 表达式 源自MSDN 多个表 导出EXCEL 代码 (分享) C# 参考之方法参数关键字:params、ref及out (收集) nchar,char,varchar 与nvarchar区别 (收集) - chinachen 抽象类与接口区别 (收集) virtual 与 Abstract 区别
android 使用sqlite几种方式。
chinachen · 2010-09-11 · via 博客园 - chinachen

1.The basic databaseHandler

先看代码:

package huuah.db;import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.SQLException;public class databaseHelper extends SQLiteOpenHelper {private static final String DBNAME = "myfancydatabase";
private databaseHelper myDBHelper;
private SQLiteDatabase myDB;private final Context myContext;public databaseHelper(Context context) {
super(context, DBNAME, null, 2);
this.myContext = context;
}

@Override

public void onCreate(SQLiteDatabase db) {
}

@Override

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public databaseHelper open() throws SQLException {
myDBHelper
= new databaseHelper(myContext);
myDB
= myDBHelper.getWritableDatabase();
return this;
}
}

databaseHandler  是连接sqlite最基本类。当 open()函数被调用时,android会创建一个新的数据库,并命名为myfancydatabase

且数据库文件路径是 /data/data/你的包名/databases/.

2. Copying from assets to database path

把已有的数据库拷贝到程序的数据库目录。

看代码:

public void createDatabase() throws IOException {

InputStream assetsDB

= myContext.getAssets().open("localdb");
OutputStream dbOut
= new FileOutputStream("/data/data/huuah.db/database/myfancydatabase");byte[] buffer = new byte[1024];
int length;
while ((length = assetsDB.read(buffer))>0){
dbOut.write(buffer,
0, length);
}

dbOut.flush();
dbOut.close();
assetsDB.close();
}

这个函数,也就是拷贝一个文件到指定目录。作用是 将assets 里的localdb数据库拷贝到程序默认数据库目录下

/data/data/包名/databases/新数据库名

 OK   拷贝完成,  就可直接使用了。

3。 Using DDMS or the ADB tool

使用DDMS  

myeclipse 菜单  选择Perspective ->Other->DDMS 

OK  弹出DDMS  界面, 其中File Explorer  窗口 就可以导入导出数据库文件或其他类型文件。

OK   三种方式,目的一致,根据实际需要选择。没有特别的要求, 比如需要初始化大量的数据,可以选择第2种方式。 作为配置参数 可以选第一种,或者XML。。。 个人意见,欢迎讨论。