Note that there are some explanatory texts on larger screens.

plurals
  1. POMy Database is not working
    text
    copied!<p>I have tried to implement a database in android and while running my application it is getting stopped without entering in to the activities. I am giving my log cat below,I need some good suggestions to overcome the error.</p> <pre><code> 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 to 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): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180) 08-16 05:40:15.381: E/AndroidRuntime(1096): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230) 08-16 05:40:15.381: E/AndroidRuntime(1096): at android.app.ActivityThread.access$600(ActivityThread.java:141) 08-16 05:40:15.381: E/AndroidRuntime(1096): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234) 08-16 05:40:15.381: E/AndroidRuntime(1096): at android.os.Handler.dispatchMessage(Handler.java:99) 08-16 05:40:15.381: E/AndroidRuntime(1096): at android.os.Looper.loop(Looper.java:137) 08-16 05:40:15.381: E/AndroidRuntime(1096): at android.app.ActivityThread.main(ActivityThread.java:5041) 08-16 05:40:15.381: E/AndroidRuntime(1096): at java.lang.reflect.Method.invokeNative(Native Method) 08-16 05:40:15.381: E/AndroidRuntime(1096): at java.lang.reflect.Method.invoke(Method.java:511) 08-16 05:40:15.381: E/AndroidRuntime(1096): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) 08-16 05:40:15.381: E/AndroidRuntime(1096): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 08-16 05:40:15.381: E/AndroidRuntime(1096): at 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): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method) 08-16 05:40:15.381: E/AndroidRuntime(1096): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882) 08-16 05:40:15.381: E/AndroidRuntime(1096): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493) 08-16 05:40:15.381: E/AndroidRuntime(1096): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588) 08-16 05:40:15.381: E/AndroidRuntime(1096): at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58) 08-16 05:40:15.381: E/AndroidRuntime(1096): at android.database.sqlite.SQLiteStatement.&lt;init&gt;(SQLiteStatement.java:31) </code></pre> <p>It says about a syntax error I think but I couldn't find any ..giving the code below</p> <pre><code> 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 from version "+ oldVersion+"to"+newVersion+",which will destroy all data"); db.execSQL("DROP TABLE IF EXISTS"+TABLE_COMMENTS); onCreate(db); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload