android - My Database is not working -
i have tried implement database in android , while running application getting stopped without entering in activities. giving log cat below,i need suggestions overcome error.
08-16 05:40:15.381: e/androidruntime(1096): fatal exception: main 08-16 05:40:15.381: e/androidruntime(1096): java.lang.runtimeexception: unable start activity componentinfo{com.de.vogella.android.sqlite.first/com.de.vogella.android.sqlite.first.testdatabaseactivity}: android.database.sqlite.sqliteexception: near "tablecomments": syntax error (code 1): , while compiling: create tablecomments(_idinteger primary key autoincrementcommenttext not null); 08-16 05:40:15.381: e/androidruntime(1096): @ android.app.activitythread.performlaunchactivity(activitythread.java:2180) 08-16 05:40:15.381: e/androidruntime(1096): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2230) 08-16 05:40:15.381: e/androidruntime(1096): @ android.app.activitythread.access$600(activitythread.java:141) 08-16 05:40:15.381: e/androidruntime(1096): @ android.app.activitythread$h.handlemessage(activitythread.java:1234) 08-16 05:40:15.381: e/androidruntime(1096): @ android.os.handler.dispatchmessage(handler.java:99) 08-16 05:40:15.381: e/androidruntime(1096): @ android.os.looper.loop(looper.java:137) 08-16 05:40:15.381: e/androidruntime(1096): @ android.app.activitythread.main(activitythread.java:5041) 08-16 05:40:15.381: e/androidruntime(1096): @ java.lang.reflect.method.invokenative(native method) 08-16 05:40:15.381: e/androidruntime(1096): @ java.lang.reflect.method.invoke(method.java:511) 08-16 05:40:15.381: e/androidruntime(1096): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:793) 08-16 05:40:15.381: e/androidruntime(1096): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:560) 08-16 05:40:15.381: e/androidruntime(1096): @ dalvik.system.nativestart.main(native method) 08-16 05:40:15.381: e/androidruntime(1096): caused by: android.database.sqlite.sqliteexception: near "tablecomments": syntax error (code 1): , while compiling: create tablecomments(_idinteger primary key autoincrementcommenttext not null); 08-16 05:40:15.381: e/androidruntime(1096): @ android.database.sqlite.sqliteconnection.nativepreparestatement(native method) 08-16 05:40:15.381: e/androidruntime(1096): @ android.database.sqlite.sqliteconnection.acquirepreparedstatement(sqliteconnection.java:882) 08-16 05:40:15.381: e/androidruntime(1096): @ android.database.sqlite.sqliteconnection.prepare(sqliteconnection.java:493) 08-16 05:40:15.381: e/androidruntime(1096): @ android.database.sqlite.sqlitesession.prepare(sqlitesession.java:588) 08-16 05:40:15.381: e/androidruntime(1096): @ android.database.sqlite.sqliteprogram.<init>(sqliteprogram.java:58) 08-16 05:40:15.381: e/androidruntime(1096): @ android.database.sqlite.sqlitestatement.<init>(sqlitestatement.java:31)
it says syntax error think couldn't find ..giving code below
public class mysqlitehelper extends sqliteopenhelper { public static final string table_comments="comments"; public static final string column_id="_id"; public static final string column_comment="comment"; private static final string database_name="comments.db"; private static int database_version=1; //database creation sql statements private static final string database_create="create table"+table_comments+" ("+column_id+"integer primary key autoincrement"+column_comment+"text not null);"; public mysqlitehelper(context context) { super(context, database_name, null, database_version); // todo auto-generated constructor stub } @override public void oncreate(sqlitedatabase database) { // todo auto-generated method stub database.execsql(database_create); } @override public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { // todo auto-generated method stub log.w(mysqlitehelper.class.getname(),"upgrading database version "+ oldversion+"to"+newversion+",which destroy data"); db.execsql("drop table if exists"+table_comments); oncreate(db); } }
you're missing few spaces in create statement.
try using:
private static final string database_create="create table " + table_comments + " (" + column_id + " integer primary key autoincrement " + column_comment + " text not null);"
Comments
Post a Comment