SQLite,是一款轻型的数据库,是遵守ACID的关联式
数据库管理系统,它的
设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流的
操作系统,同时能够跟很多
程序语言相结合,比如 Tcl、C#、
PHP、
Java等,还有ODBC接口,同样比起Mysql、PostgreSQL这两款开源世界著名的数据库
管理系统来讲,它的处理速度比他们都快。SQLite第一个
Alpha版本诞生于2000年5月. 至今已经有10个年头,SQLite也迎来了一个版本 SQLite 3已经发布。
还有一件事,大家下载的时候,不要加数据库连接驱动包。本项目是不用的。
先让我们看一下图先。
业务类
package com.smart.dh;import java.util.Iterator;import java.util.List;import android.test.AndroidTestCase;import android.util.Log;import com.smart.domain.Person;import com.smart.service.PersonService;public class PersonServiceTest extends AndroidTestCase {private static final String TAG="PersonServiceTest";//保存数据。public void testSave() throws Exception{ PersonService personService=new PersonService(this.getContext());// personService.save(new Person("老梁",(short)23)); for (int i = 0; i < 10; i++) { personService.save(new Person("llb"+i,(short)(i+1))); } }//查询public void testFind() throws Exception{ PersonService personService=new PersonService(this.getContext()); Person person=personService.find(1); Log.i(TAG, person.toString()); // personService.save(new Person("老梁",(short)23));}//更新语句public void testUpdate() throws Exception{ PersonService personService=new PersonService(this.getContext()); Person person=personService.find(1); person.setName("smart"); personService.update(person); Log.i(TAG, person.toString()); }//获得所有的条数public void testGetCount() throws Exception{ PersonService personService=new PersonService(this.getContext()); Log.i(TAG, String.valueOf(personService.getCount())); }//分页功能public void testGetScrollData() throws Exception{ PersonService personService=new PersonService(this.getContext()); List<Person> persons=personService.getScrollData(0, 20);//从0条到20条的数据 for(Person person:persons){ Log.i(TAG, person.toString()); } }public void testDelete() throws Exception{ PersonService personService=new PersonService(this.getContext()); personService.delete(1,2,3);//删除1.2.3三条记录}
javaBean类package com.smart.domain;public class Person {@Overridepublic String toString() { return "personid="+personid+",name="+name+",age="+age;}public int personid;public String name;public Short age;public int getPersonid() { return personid;}public void setPersonid(int personid) { this.personid = personid;}public String getName() { return name;}public void setName(String name) { this.name = name;}// 增加一个构造器public Person(int personid, String name, Short age) { super(); this.personid = personid; this.name = name; this.age = age;}//创建构造器public Person(String name, short age) { this.name