在cmd窗口中查询android的sqlite3数据库表之步骤
本文主要是写了一个android程序对sqlite3中数据库的employee表的插入、删除的操作,然后在cmd窗口中用sql命令查询employee表的操作过程.
1、第一步:首先把程序写好.
1.1、创建一个MainActivity类,代码如下:
package com.example.datastorege;import com.example.datastorege.dao.EmployeeDao;import com.example.datastorege.model.Employee;import android.test.AndroidTestCase;import android.util.Log;public class EmployeeDaoJunit extends AndroidTestCase{private static final String TAG="EmployeeDaoJunit";public void add(){EmployeeDao employeeDao=new EmployeeDao(this.getContext());employeeDao.insert(new Employee(2,"tangfq",1));Log.i(TAG, "EmployeeDao--->insert");}public void delete(){EmployeeDao employeeDao=new EmployeeDao(this.getContext());employeeDao.delete(1);Log.i(TAG, "EmployeeDao--->delete");}}
以上就是要写的程序.查询和修改在测试类添加就行了.操作和新增、删除类似.
2、第二步:运行上面写的程序及操作sqlite3数据库.
2.1、运行EmployeeDaoJunit ,在运行它之前,要先运行sqlite3.exe,运行起后才执行EmployeeDaoJunit ,当junit运行绿色时,则证明写正确了.此时,在运行中输入"cmd"--->adb shell---->ls---->cd data---->cd data--->(在eclipse中打开DDMS Pespective,点击"File Explorer"查看,data--->data--->你的项目名包路径,如我的是com.example.datastorege)--->databases--->你的数据库名,我的数据库名为testDb.db--->sqlite3 testDb.db--->select id,empName,sex from employee;---->显示操作的employee表的结果.
操作的步骤是上面所描述的,如果有什么疑问或错误之处,敬请留言!谢谢了!