java - How do you search or sort in SQLite Database? -
i have application stores information in database based on information 5 text fields. i'm having trouble being able sort through fields or sorting 1 field. also, method order clause go in? snippets of code database below:
public static final string mydatabase_name = "my_database"; public static final string mydatabase_table = "my_table"; public static final int mydatabase_version = 1; public static final string key_content = "content"; public static final string lastname = "lastname"; public static final string firstname = "firstname"; public static final string school = "school"; public static final string email = "email"; public static final string intrest = "intrest"; cursor d = sqlitedatabase.rawquery("select * " + mydatabase_table + "order " + lastname + " asc" , null); while (d.movetonext()) { int sort = d.getcolumnindex(lastname); int sort2 = d.getcolumnindex(intrest); string lastname = d.getstring(sort); string intrest = d.getstring(sort2); system.out.println("got student " + lastname + " likes " + intrest); }
try use (cursor.getcount() > 0) method , (cursor != null) condition in code check whether gets data or not. have shown below. , try use log query perfection , put query in sqlite database check whether working or not.
cursor d = sqlitedatabase.rawquery("select * " + mydatabase_table + " order " + lastname + " asc" , null); // here have edited space before order word starts. please note log.d("query",">>>>"+select * " + mydatabase_table + " order " + lastname + " asc"); // check query going right way or not using local database. if(d != null){ if(d.getcount() > 0){ // check 1 or more data d.movetofirst(); do{ int sort = d.getcolumnindex(lastname); int sort2 = d.getcolumnindex(intrest); string lastname = d.getstring(sort); string intrest = d.getstring(sort2); system.out.println("got student " + lastname + " likes " + intrest); } while (d.movetonext()); } } try this. hope you.
Comments
Post a Comment