Syntax error with SQLite query in Android -
i trying create new sqlite database in android. here oncreate method:
public static final string database_name = "eventlist.db"; public static final string table_name = "event_table"; public static final string col1 = "id"; public static final string col2 = "eventname"; public static final string col3 = "unixtimestamp"; public static final string col4 = "participants"; public static final string col5 = "location"; public static final string col6 = "locationname"; @override public void oncreate(sqlitedatabase sqlitedatabase) { string createtable = "create table " + table_name + "(id integer primary key autoincriment, " + " eventname text, unixtimestamp integer, participants text, location text, locationname text)"; sqlitedatabase.execsql(createtable); }
this throwing syntax error:
android.database.sqlite.sqliteexception: near "autoincriment": syntax error (code 1): , while compiling: create table event_table(id integer primary key autoincriment, eventname text, unixtimestamp integer, participants text, location text, locationname text)
please note participants going custom object, , location going latlng object.
how can solve error?
you have typo in
string createtable = "create table " + table_name + "(id integer primary key autoincriment, "
note autoincriment
should spelt autoincrement
plus id should _id also, have gone trouble of setting constants why not use them save on further potential typos? e.g. instead of
+ " eventname text
why not use
+ col2 + " text
etc...
could suggest read on how create databases here superb tutorial , shows best practices
Comments
Post a Comment