关系型数据库需要自己直接写sql操作RDBMS,有了ORM映射库就方便多了,直接写读对象;
把这两天遇到的问题总结下:
1.安装,orm类库比较多,推荐时候ormLite;
官网和参考博文:http://blog.csdn.net/yzzst/article/details/9359271
2.遇见了 unable to run insert stmt on object ormlite
类似:http://stackoverflow.com/questions/11722976/arraylist-with-2-fields-into-ormlite-android
http://stackoverflow.com/questions/14937723/android-ormlite-sqlexception-when-persisting-class-containing-foreigncollection
http://stackoverflow.com/questions/14559993/java-sql-sqlexception-unable-to-run-insert-stmt-on-object
但都没有找到什么关键答案,还是得靠自己。写了个demo一点一点测试;
发现就是执行第一个helper使用可以,以后就总是不行,报“ unable to run insert stmt on object ormlite” 头开始还以为是序列化问题,后来把序列化 去掉还是不行;
3.在android中要注意,如果每次覆盖安装,当你的bean结构换了,实际上对应的db表结构也就换了,所以会老是报错,所以最好在更改后,完全卸载;
4.返现使用第一个helper会调用oncreate函数,new第二个其他对象的helper时就不执行 oncreate了,导致在oncreate里面的创建表操作没有被执行。后来没办法,在第一个helper的oncreate中把table都去做了createTableIfNotExists()