SQLite,是一款轻型的数据库,是遵守ACID的关联式数据库管理系统,它的设计目标是嵌入式的,而且目前已经在很多嵌入式产品中使用了它,它占用资源非常的低,在嵌入式设备中,可能只需要几百K的内存就够了。它能够支持Windows/Linux/Unix等等主流的操作系统,同时能够跟很多程序语言相结合,比如 Tcl、C#、PHP、Java等,还有ODBC接口,同样比起Mysql、PostgreSQL这两款开源世界著名的数据库管理系统来讲,它的处理速度比他们都快。SQLite第一个Alpha版本诞生于2000年5月.至今已经有10个年头,SQLite也迎来了一个版本SQLite3已经发布。
还有一件事,大家下载的时候,不要加数据库连接驱动包。本项目是不用的。
先让我们看一下图先。
|
viewsourceprint?
003 | importjava.util.Iterator;
|
005 | importandroid.test.AndroidTestCase; |
006 | importandroid.util.Log; |
007 | importcom.smart.domain.Person;
|
008 | importcom.smart.service.PersonService; |
009 | public class PersonServiceTestextendsAndroidTestCase{ |
010 | private static finalStringTAG= "PersonServiceTest" ; |
013 | public void testSave()throwsException{ |
014 | PersonServicepersonService= new
PersonService( this .getContext()); |
015 | //personService.save(newPerson("老梁",(short)23)); |
017 | personService.save( new
Person( "llb" +i,( short )(i+1))); |
025 | public void testFind()throwsException{ |
026 | PersonServicepersonService= new
PersonService( this .getContext()); |
027 | Personperson=personService.find(1); |
028 | Log.i(TAG,person.toString()); |
030 | //personService.save(newPerson("老梁",(short)23)); |
033 | public void testUpdate()throwsException{ |
034 | PersonServicepersonService= new
PersonService( this .getContext()); |
035 | Personperson=personService.find(1); |
036 | person.setName( "smart" ); |
037 | personService.update(person); |
039 | Log.i(TAG,person.toString()); |
043 | public void testGetCount()throwsException{ |
044 | PersonServicepersonService= new
PersonService( this .getContext()); |
045 | Log.i(TAG,String.valueOf(personService.getCount())); |
050 | public void testGetScrollData()throwsException{
|
051 | PersonServicepersonService= new
PersonService( this .getContext()); |
052 | List<Person>persons=personService.getScrollData(0,20); //从0条到20条的数据 |
053 | for (Personperson:persons){
|
054 | Log.i(TAG,person.toString()); |
060 | public void testDelete()throwsException{ |
061 | PersonServicepersonService= new
PersonService( this .getContext()); |
062 | personService.delete(1,2,3); //删除1.2.3三条记录 |
074 | packagecom.smart.domain; |
077 | public StringtoString(){
|
079 | return
"personid=" +personid+ ",name=" +name+ ",age=" +age; |
084 | public int getPersonid(){ |
087 | public void setPersonid( int
personid){ |
088 | this .personid=personid; |
090 | public StringgetName(){
|
093 | public void setName(Stringname){ |
097 | public Person( int personid,Stringname,Shortage){
|
099 | this .personid=personid; |
104 | public Person(Stringname, short age){
|
112 | public void setAge(Shortage){ |
119 | packagecom.smart.service;
|
120 | importandroid.content.Context;
|
121 | importandroid.database.sqlite.SQLiteDatabase; |
122 | importandroid.database.sqlite.SQLiteDatabase.CursorFactory; |
123 | importandroid.database.sqlite.SQLiteOpenHelper; |
124 | public class DataBaseOpenHelperextendsSQLiteOpenHelper{
|
126 | private static finalStringDBNAME= "smrtDataBase" ; |
128 | private static final int
version=1; |
130 | public DataBaseOpenHelper(Contextcontext){
|
131 | super(context,DBNAME,
null ,version); |
135 | public void onCreate(SQLiteDatabasedb){ |
136 | db.execSQL( "CREATETABLEperson(personidintegerprimarykeyautoincrement,namevarchar(20),ageINTEGER)" ); |
140 | public void onUpgrade(SQLiteDatabasedb, int
oldVersion, int
newVersion){ |
141 | db.execSQL( "EROPTABLEIFEXISTSperson" ); |
刚学用这个东西,不知道在哪里上传小项目,希望大家告诉我一下。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理