与android database 交互(chapter 14-Working with the SQLite Database)

来源:互联网 发布:mysql从零开始学 编辑:程序博客网 时间:2024/05/17 23:54

access数据库的三种方式(数据库通常位于/data/data/<app name>下)

1. adb shell(唯一可直接访问虚机或物理机上的数据库的方式)

在命令行模式使用adb -e shell 进入虚机shell , adb -d shell进入物理机shell(如果只有一个虚机或物理机在运行)或者 adb -s <device name> shell

cd c:\androidsdk\sdk\platform-tools

adb -e shell

sqlite3


然后可运行sqlite3的命令。比如:

  • .tables 列出所有表格
  • .schema [tablename] 显示表格的创建statement

有关sqlite详细文档参考:http://www.sqlite.org/sqlite.html, section Special commands to sqlite3.

以下两种只能操作本机上的数据库(有UI)

2. eclipse 的JDBC driver

3. sqlite expert personal edition(www.sqliteexpert.com)

辅助的数据库工具:SQLiteAssetHelper class(https://github.com/jgilfelt/android-sqlite-asset-helper) 。该类实例化后会将\assets\databases 目录下的数据库拷贝到应用的私有空间,这样可以免去测试时创建和升级数据库的麻烦


主要类:

SQLiteDatabase - 用于与SQLite数据库直接交互

SQLiteQueryBuilder - 用于创建数据查询语句

SQLiteStatement - 用于执行SQL查询

SQLiteCursor - 用于cursor操作

SQLiteOpenHelper - 用于数据库的打开,创建和升级




0 0
原创粉丝点击