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

推荐订阅源

S
Schneier on Security
F
Fortinet All Blogs
B
Blog
GbyAI
GbyAI
P
Proofpoint News Feed
量子位
The Register - Security
The Register - Security
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
云风的 BLOG
云风的 BLOG
V
Visual Studio Blog
B
Blog RSS Feed
WordPress大学
WordPress大学
Recorded Future
Recorded Future
Recent Announcements
Recent Announcements
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Secure Thoughts
雷峰网
雷峰网
Stack Overflow Blog
Stack Overflow Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Webroot Blog
Webroot Blog
AWS News Blog
AWS News Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The GitHub Blog
The GitHub Blog
爱范儿
爱范儿
O
OpenAI News
月光博客
月光博客
H
Hacker News: Front Page
S
Security Affairs
W
WeLiveSecurity
The Hacker News
The Hacker News
aimingoo的专栏
aimingoo的专栏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Help Net Security
Help Net Security
MongoDB | Blog
MongoDB | Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
D
Docker
T
The Blog of Author Tim Ferriss
Spread Privacy
Spread Privacy
Blog — PlanetScale
Blog — PlanetScale
J
Java Code Geeks
S
Securelist
Microsoft Azure Blog
Microsoft Azure Blog
TaoSecurity Blog
TaoSecurity Blog
T
Threat Research - Cisco Blogs
M
MIT News - Artificial intelligence
A
About on SuperTechFans

博客园 - 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。。。 个人意见,欢迎讨论。