package cn.class3g.db; … public class PersonServiceTest extends AndroidTestCase { public void testSave() throws Throwable{ PersonService service = new PersonService(this.getContext()); Person person = new Person(); person.setName("zhangxiaoxiao"); service.save(person); Person person2 = new Person(); person2.setName("laobi"); service.save(person2); Person person3 = new Person(); person3.setName("lili"); service.save(person3); Person person4 = new Person(); person4.setName("zhaoxiaogang"); service.save(person4); } public void testUpdate() throws Throwable{ PersonService ps = new PersonService(this.getContext()); Person person = new Person("Ton", 122); ps.update(person, 2);//需要实现查看数据库中Ton的id值 } public void testFind() throws Throwable{ PersonService ps = new PersonService(this.getContext()); Person person = ps.find(2); Log.i("TAG",person.toString()); } public void testDelete() throws Throwable{ PersonService ps = new PersonService(this.getContext()); ps.delete(2); } public void testScroll() throws Throwable{ PersonService service = new PersonService(this.getContext()); List<Person> personList = service.getScrollData(3, 2); Log.i("TAG",personList.toString()); } public void testCount() throws Throwable{ PersonService service = new PersonService(this.getContext()); long count = service.getRecordsCount(); Log.i("TAG", String.valueOf(count)); } }
常见异常
android.database.sqlite.SQLiteException:Can't upgrade read-only database from version 0 to 1:
这个错误基本上都是sql有问题导致的,仔细检查sql即可。