android - database "CREATE TABLE IF NOT EXISTS" syntax error -


my code contains database class.while running shows error regarding create table if not exists statement.please give me solution correct error.

clasdbopenhelper.java

package example.events1;  import android.content.context; import android.database.cursor; import android.database.sqlexception; import android.database.sqlite.sqlitedatabase; import android.database.sqlite.sqliteopenhelper;   public class classdbopenhelper extends sqliteopenhelper {      public static final string key_rowid = "_id";     public static final string key_desc = "countdesc";     public static final string key_date = "countdate";     public static final string key_event = "countevent";     public static final string database_name= "countdb";     public static final string database_table = "countable";     public static final int database_version = 1;       public classdbopenhelper(context context) {         super(context, database_name, null, database_version);         // todo auto-generated constructor stub     }      @override     public void oncreate(sqlitedatabase db) {          string create_contacts_table = "create table if not exists" + database_table + "("                 + key_rowid + " integer primary key autoincrement, " + key_desc + " text, " + key_date + " text, " + key_event + " text  )";         db.execsql(create_contacts_table);     }       @override     public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {         // todo auto-generated method stub         db.execsql("drop table if exits " + database_table);         oncreate(db);      }       public cursor fetchallevents() {         sqlitedatabase db = this.getreadabledatabase();          cursor mcursor = db.query(database_table, new string[] {key_rowid,                 key_desc, key_date, key_event },         null, null, null, null, null );         if (mcursor != null) {         mcursor.movetofirst();         }         return mcursor;    }      public cursor fetcheventbyname(string inputtext,string datevalue ) throws sqlexception {         sqlitedatabase db = this.getreadabledatabase();          cursor mcursor = null;         if (inputtext == null || inputtext.length () == 0) {         mcursor = db.query(database_table, new string[] {key_rowid,                 key_desc, key_date, key_event },         null, null, null, null, null);         }         else {             mcursor  =  db.rawquery("select * countable countdesc = ? , countdate = ?", new string[] {inputtext,datevalue});                    }          if (mcursor != null) {         mcursor.movetofirst();         }         return mcursor;    }      public void delete(long id) {         sqlitedatabase db = this.getreadabledatabase();          db.delete(database_table, key_rowid + " = ?",                 new string[] { string.valueof(id )});         db.close();     } } 

logcat

08-20 04:32:26.411: e/sqlitelog(839): (1) near "existscountable": syntax error 08-20 04:32:26.681: e/androidruntime(839): fatal exception: main 08-20 04:32:26.681: e/androidruntime(839): java.lang.runtimeexception: unable start activity componentinfo{example.events1/example.events1.getclicker}: android.database.sqlite.sqliteexception: near "existscountable": syntax error (code 1): , while compiling: create table if not existscountable(_id integer primary key autoincrement, countdesc text, countdate text, countevent text  ) 08-20 04:32:26.681: e/androidruntime(839):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 08-20 04:32:26.681: e/androidruntime(839):  @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 08-20 04:32:26.681: e/androidruntime(839):  @ android.app.activitythread.access$600(activitythread.java:141) 08-20 04:32:26.681: e/androidruntime(839):  @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 08-20 04:32:26.681: e/androidruntime(839):  @ android.os.handler.dispatchmessage(handler.java:99) 08-20 04:32:26.681: e/androidruntime(839):  @ android.os.looper.loop(looper.java:137) 08-20 04:32:26.681: e/androidruntime(839):  @ android.app.activitythread.main(activitythread.java:5041) 08-20 04:32:26.681: e/androidruntime(839):  @ java.lang.reflect.method.invokenative(native method) 08-20 04:32:26.681: e/androidruntime(839):  @ java.lang.reflect.method.invoke(method.java:511) 08-20 04:32:26.681: e/androidruntime(839):  @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 08-20 04:32:26.681: e/androidruntime(839):  @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 08-20 04:32:26.681: e/androidruntime(839):  @ dalvik.system.nativestart.main(native method) 08-20 04:32:26.681: e/androidruntime(839): caused by: android.database.sqlite.sqliteexception: near "existscountable": syntax error (code 1): , while compiling: create table if not existscountable(_id integer primary key autoincrement, countdesc text, countdate text, countevent text  ) 08-20 04:32:26.681: e/androidruntime(839):  @ android.database.sqlite.sqliteconnection.nativepreparestatement(native method) 08-20 04:32:26.681: e/androidruntime(839):  @ android.database.sqlite.sqliteconnection.acquirepreparedstatement(sqliteconnection.java:882) 08-20 04:32:26.681: e/androidruntime(839):  @ android.database.sqlite.sqliteconnection.prepare(sqliteconnection.java:493) 08-20 04:32:26.681: e/androidruntime(839):  @ android.database.sqlite.sqlitesession.prepare(sqlitesession.java:588) 08-20 04:32:26.681: e/androidruntime(839):  @ android.database.sqlite.sqliteprogram.<init>(sqliteprogram.java:58) 08-20 04:32:26.681: e/androidruntime(839):  @ android.database.sqlite.sqlitestatement.<init>(sqlitestatement.java:31) 08-20 04:32:26.681: e/androidruntime(839):  @ android.database.sqlite.sqlitedatabase.executesql(sqlitedatabase.java:1663) 08-20 04:32:26.681: e/androidruntime(839):  @ android.database.sqlite.sqlitedatabase.execsql(sqlitedatabase.java:1594) 08-20 04:32:26.681: e/androidruntime(839):  @ example.events1.classdbopenhelper.oncreate(classdbopenhelper.java:31) 08-20 04:32:26.681: e/androidruntime(839):  @ android.database.sqlite.sqliteopenhelper.getdatabaselocked(sqliteopenhelper.java:252) 08-20 04:32:26.681: e/androidruntime(839):  @ android.database.sqlite.sqliteopenhelper.getreadabledatabase(sqliteopenhelper.java:188) 08-20 04:32:26.681: e/androidruntime(839):  @ example.events1.classdbopenhelper.fetcheventbyname(classdbopenhelper.java:57) 08-20 04:32:26.681: e/androidruntime(839):  @ example.events1.getclicker.oncreate(getclicker.java:36) 08-20 04:32:26.681: e/androidruntime(839):  @ android.app.activity.performcreate(activity.java:5104) 08-20 04:32:26.681: e/androidruntime(839):  @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1080) 08-20 04:32:26.681: e/androidruntime(839):  @ android.app.activitythread.performlaunchactivity(activitythread.java:2144) 08-20 04:32:26.681: e/androidruntime(839):  ... 11 more 

give space after exists this

string create_contacts_table = "create table if not exists " + database_table + "("             + key_rowid + " integer primary key autoincrement, " + key_desc + " text, " + key_date + " text, " + key_event + " text  )"; 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -