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

推荐订阅源

The Hacker News
The Hacker News
F
Full Disclosure
Cloudbric
Cloudbric
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
N
News and Events Feed by Topic
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
B
Blog
GbyAI
GbyAI
C
Check Point Blog
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Recorded Future
Recorded Future
The Last Watchdog
The Last Watchdog
N
News and Events Feed by Topic
T
The Blog of Author Tim Ferriss
O
OpenAI News
V
V2EX
人人都是产品经理
人人都是产品经理
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
WordPress大学
WordPress大学
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Security @ Cisco Blogs
C
Cisco Blogs
Security Latest
Security Latest
S
Security Affairs
V
Visual Studio Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
Last Week in AI
Last Week in AI
AWS News Blog
AWS News Blog
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
PCI Perspectives
PCI Perspectives
博客园_首页
U
Unit 42
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
N
Netflix TechBlog - Medium
L
LINUX DO - 热门话题
H
Hacker News: Front Page

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