android - SQLiteException: (near "Table": syntax error) -


failure 1 (near "table": syntax error) on 0x1d2440 when preparing 'create table table(_id integer primary key, pname text not null,gender text not null,age text not null,weight text not null,height text not null)'. 

im new android , can't find similar errors. i've checked code , thing that's been pestering me finishing application.

i thank guys in advance.

here's code:

public class data { public static final string key_rowid="_id"; public static final string key_name="pname"; public static final string key_gender="gender"; public static final string key_age="age"; public static final string key_height="height"; public static final string key_weight="weight";  private static final string database_name="data"; private static final string database_table="table"; private static final int database_version = 1;  private dbhelper ourhelper; private final context ourcontext; private sqlitedatabase ourdatabase;  private static class dbhelper extends sqliteopenhelper{      public dbhelper(context context) {         super(context, database_name, null, database_version);      }      @override     public void oncreate(sqlitedatabase db) {           string create_database_table = "create table " + database_table + "("                 + key_rowid + " integer primary key," +                   key_name  + " text not null,"                 + key_gender + " text not null,"                  + key_age + " text not null,"                  + key_weight + " text not null,"                  + key_height + " text not null"                  + ")";       db.execsql(create_database_table);        }      @override     public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {          db.execsql("drop table if exists" + database_table);         oncreate(db);      }  } public data(context c){     ourcontext = c; } public data open(){     ourhelper = new dbhelper(ourcontext);     ourdatabase = ourhelper.getwritabledatabase();     return this; } public void close(){     ourhelper.close(); } public long createentry(string pname, string age, string gender,         string height, string weight) {      contentvalues cv = new contentvalues();     cv.put(key_name, pname);     cv.put(key_gender, gender);     cv.put(key_age, age);     cv.put(key_height, height);     cv.put(key_weight, weight);     return ourdatabase.insert(database_table, null, cv);   } 

}

1) change ::

private static final string database_table="table";

to name not sqlite reserved word

for example :: private static final string database_table="mytable";

2) inside onupgrade method add space in query:

@override   public void onupgrade(sqlitedatabase db, int oldversion, int newversion) {           //db.execsql("drop table if exists" + database_table);           db.execsql("drop table if exists " + database_table);           oncreate(db);       }  

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -