Android: SQLite database query not returning any records -
i created , populated sqlite database firefox sqlite manager. copied .sqlite file assets folder of android project.
my aim use records populate spinner. when query database, cursor displays columns no records.
my databasehandler
class extends sqliteopenhelper
, contains methods oncreate
, onupgrade
, getalloffices
.
public list<string> getalloffices(){ list<string> offices = new arraylist<string>(); // select query string selectquery = "select officeid _id, officename " + table_office; sqlitedatabase db = this.getreadabledatabase(); cursor cursor = db.rawquery(selectquery, null); // looping through rows , adding list if (cursor.movetofirst()) { { offices.add(cursor.getstring(1)); } while (cursor.movetonext()); } // closing connection cursor.close(); db.close(); // returning offices return offices; }
any ideas on why records not returned appreciated.
try this:
public list<string> getalloffices(){ list<string> offices = new arraylist<string>(); // select query string selectquery = "select officeid _id, officename " + table_office; sqlitedatabase db = this.getreadabledatabase(); cursor cursor = db.rawquery(selectquery, null); // looping through rows , adding list if (cursor.movetofirst()) { { offices.add(cursor.getstring(cursor.getcolumnindex("_id"))); } while (cursor.movetonext()); } // closing connection cursor.close(); db.close(); // returning offices return offices; }
basically ensure using correct column index. otherwise if using eclipse try cellobject plugin browse database , make sure table populated expected: http://marketplace.eclipse.org/content/cellobject-sqlite-xml-browser#.uwou5rabd3g
Comments
Post a Comment