SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如 Tcl、C#、PHP、Java等,还有ODBC接口,同样比起Mysql、PostgreSQL这两款开源世界著名的数据库管理系统来讲,它的处理速度比他们都快。SQLite第一个Alpha版本诞生于2000年5月. 至今已经有10个年头,SQLite也迎来了一个版本 SQLite 3已经发布。 还有一件事,大家下载的时候,不要加数据库连接驱动包。本项目是不用的。 先让我们看一下图先。 |
![](https://i-blog.csdnimg.cn/blog_migrate/f7f4b7b6694aa8478443b94272e20fec.jpeg)
003 | import java.util.Iterator; |
004 | import java.util.List; |
005 | import android.test.AndroidTestCase; |
006 | import android.util.Log; |
007 | import com.smart.domain.Person; |
008 | import com.smart.service.PersonService; |
009 | public class PersonServiceTest extends AndroidTestCase { |
010 | private static final String TAG= "PersonServiceTest" ; |
013 | public void testSave() throws Exception{ |
014 | PersonService personService= new PersonService( this .getContext()); |
016 | for ( int i = 0; i < 10; i++) { |
017 | personService.save( new Person( "llb" +i,( short )(i+1))); |
025 | public void testFind() throws Exception{ |
026 | PersonService personService= new PersonService( this .getContext()); |
027 | Person person=personService.find(1); |
028 | Log.i(TAG, person.toString()); |
033 | public void testUpdate() throws Exception{ |
034 | PersonService personService= new PersonService( this .getContext()); |
035 | Person person=personService.find(1); |
036 | person.setName( "smart" ); |
037 | personService.update(person); |
039 | Log.i(TAG, person.toString()); |
043 | public void testGetCount() throws Exception{ |
044 | PersonService personService= new PersonService( this .getContext()); |
045 | Log.i(TAG, String.valueOf(personService.getCount())); |
050 | public void testGetScrollData() throws Exception{ |
051 | PersonService personService= new PersonService( this .getContext()); |
052 | List<Person> persons=personService.getScrollData(0, 20); |
053 | for (Person person:persons){ |
054 | Log.i(TAG, person.toString()); |
060 | public void testDelete() throws Exception{ |
061 | PersonService personService= new PersonService( this .getContext()); |
062 | personService.delete(1,2,3); |
074 | package com.smart.domain; |
077 | public String toString() { |
079 | return "personid=" +personid+ ",name=" +name+ ",age=" +age; |
084 | public int getPersonid() { |
087 | public void setPersonid( int personid) { |
088 | this .personid = personid; |
090 | public String getName() { |
093 | public void setName(String name) { |
097 | public Person( int personid, String name, Short age) { |
099 | this .personid = personid; |
104 | public Person(String name, short age) { |
109 | public Short getAge() { |
112 | public void setAge(Short age) { |
119 | package com.smart.service; |
120 | import android.content.Context; |
121 | import android.database.sqlite.SQLiteDatabase; |
122 | import android.database.sqlite.SQLiteDatabase.CursorFactory; |
123 | import android.database.sqlite.SQLiteOpenHelper; |
124 | public class DataBaseOpenHelper extends SQLiteOpenHelper { |
126 | private static final String DBNAME = "smrtDataBase" ; |
128 | private static final int version = 1; |
130 | public DataBaseOpenHelper(Context context) { |
131 | super(context, DBNAME, null , version); |
135 | public void onCreate(SQLiteDatabase db) { |
136 | db.execSQL( "CREATE TABLE person (personid integer primary key autoincrement,name varchar(20),age INTEGER)" ); |
140 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { |
141 | db.execSQL( "EROP TABLE IF EXISTS person" ); |
刚学用这个东西,不知道在哪里上传小项目,希望大家告诉我一下。