java - Sql query is not working for SQLite database in android -


i new android. want execute sql query of selecting data id 1 10.the query m using running on db browser sqlite not in code. ab , bc static variables of class catogaries.please help.

public class quizhelper extends sqliteopenhelper { private static final int database_version =1; // database name private static final string database_name = "bcd"; // tasks table name private static final string table_quest = "quest"; // tasks table columns names  private static final string key_id = "qid"; private static final string key_ques = "question"; private static final string key_answer = "answer"; // correct option private static final string key_opta = "opta"; // option private static final string key_optb = "optb"; // option b private static final string key_optc = "optc"; // option c  private sqlitedatabase dbase;  public quizhelper(context context) {     super(context, database_name, null, database_version); }  @override public void oncreate(sqlitedatabase db) {     dbase = db;     string sql = "create table if not exists " + table_quest + " ( "             + key_id + " integer primary key autoincrement, " + key_ques             + " text, " + key_answer + " text, " + key_opta + " text, "             + key_optb + " text, " + key_optc + " text)";     db.execsql(sql);     addquestion();     // db.close(); }  private void addquestion() {     question q1 = new question("who president of india ?",       "narender modi", "hamid ansari", "pranab mukherji", "pranab        mukherji");     this.addquestion(q1);     question q2 = new question(" name of first university of india        ?", "nalanda university", "takshshila university", "bhu", "nalanda       university");     this.addquestion(q2);     question q3 = new question("which college awarded outstanding       engineering institute north award”?", "thapar university",       "g.n.d.e.c", "s.l.i.e.t", "g.n.d.e.c");     this.addquestion(q3);     question q4 = new question("name of first aircraft carrier indian      ship ?", "samudragupt", "i.n.s. vikrant", "i.n.s virat", "i.n.s.      vikrant");     this.addquestion(q4);     question q5 = new question("in town of punjab largest grain      market of asia available?", "bathinda", "khanna", "ludhiana",      "khanna");     this.addquestion(q5);     question q6 = new question("which highest dam in india?",      "bhakhra dam", "hirakud dam", "tehri dam", "tehri dam");     this.addquestion(q6);     question q7 = new question("which indian state having longest      coastline ?", "rajasthan", "gujrat", "punjab", "gujrat");     this.addquestion(q7);     question q8 = new question("name of first country print books       ?", "china", "india", "usa", "china");     this.addquestion(q8);     question q9 = new question("study of universe known as?",      "sociology", "cosmology", "petology", "cosmology");     this.addquestion(q9);     question q10 = new question("big bang theory explains ?", "origin of       universe.", "origin of sun", "laws of physics.", "origin of      universe.");     this.addquestion(q10);     question q11 = new question("which planet dwarf planet?",      "mercury", "pluto",   "venus", "pluto");     this.addquestion(q11);     }      @override      public void onupgrade(sqlitedatabase db, int oldv, int newv) {     // drop older table if existed     db.execsql("drop table if exists " + table_quest);     // create tables again     oncreate(db); }  // adding new question public void addquestion(question quest) {     // sqlitedatabase db = this.getwritabledatabase();     contentvalues values = new contentvalues();     values.put(key_ques, quest.getquestion());     values.put(key_answer, quest.getanswer());     values.put(key_opta, quest.getopta());     values.put(key_optb, quest.getoptb());     values.put(key_optc, quest.getoptc());      // inserting row     dbase.insert(table_quest, null, values); }  public list<question> getallquestions() {     list<question> queslist = new arraylist<question>();     // select query     string selectquery = "select  * " + table_quest + "where" + key_id + "between" + catogaries.bc + "and" +catogaries.ab;     dbase = this.getreadabledatabase();     cursor cursor = dbase.rawquery(selectquery, null);     // looping through rows , adding list     if (cursor.movetofirst()) {         {             question quest = new question();             quest.setid(cursor.getint(0));             quest.setquestion(cursor.getstring(1));             quest.setanswer(cursor.getstring(2));             quest.setopta(cursor.getstring(3));             quest.setoptb(cursor.getstring(4));             quest.setoptc(cursor.getstring(5));              queslist.add(quest);         } while (cursor.movetonext());     }     // return quest list     return queslist; } 

error log

  04-05 15:00:28.452 31300-31300/com.example.chaitanya.myquiz       e/androidruntime: fatal exception: main     process: com.example.chaitanya.myquiz, pid: 31300     java.lang.runtimeexception: unable start activity       componentinfo                  {com.example.chaitanya.myquiz.questionactivity}:                         android.database.sqlite.sqliteexception: no such table:                     questwhereqidbetween0and10 (code 1): , while compiling:                      select* questwhereqidbetween0and10    @    android.app.activitythread.performlaunchactivity   (activitythread.java:2305)  @    android.app.activitythread.handlelaunchactivity(activitythread.java:2365)                                                                               @ android.app.activitythread.access$800(activitythread.java:147)                                                                               @ android.app.activitythread$h.handlemessage(activitythread.java:1283)                                                                               @ android.os.handler.dispatchmessage(handler.java:102)                                                                               @ android.os.looper.loop(looper.java:135)                                                                               @ android.app.activitythread.main(activitythread.java:5237)                                                                               @ java.lang.reflect.method.invoke(native method)                                                                               @ java.lang.reflect.method.invoke(method.java:372)                                                                                @ com.android.internal.os.zygoteinit.main(zygoteinit.java:707)                                                                            caused by: android.database.sqlite.sqliteexception: no such table: questwhereqidbetween0and10 (code 1): , while compiling: select  * questwhereqidbetween0and10                                                                               @ android.database.sqlite.sqliteconnection.nativepreparestatement(native method) 

focus on exception:

no such table: questwhereqidbetween0and10

you missing space between table name , clause , , keyword etc . query makes whole string

use:

string selectquery = "select  * " + table_quest + " " + key_id + " between " + catogaries.bc + " , " +catogaries.ab; 

Comments