sqlite - Android Database Access Pattern -
is appropriate way database access in android app? should opening , closing database connections this, or should have 1 sqlitedatabase object continually run queries against? method specific column data cursor appropriate?
public list<object> getobjects() { sqlitedatabase db = sqlitedatabase.opendatabase(this.path, null, sqlitedatabase.open_readonly); list<object> ret = new arraylist<object>(); cursor cursor = db.rawquery("select * objects", null); while(cursor.movetonext()) { object obj = new object(); obj.setid(cursor.getint(cursor.getcolumnindex("id"))); obj.settitle(cursor.getstring(cursor.getcolumnindex("title"))); ret.add(obj); } db.close(); return ret; }
the singleton pattern have on final static object acces database common databases
Comments
Post a Comment