title: android.database.sqlite.SQLiteException: near "productname": syntax error (code 1): , while compiling:
body: <p>I am trying to make a database in my app. Unfortunately I am running in some trouble running my app.</p>
  
  <p>DbHandler class:</p>
  
  <pre><code>package com.example.jarno.a49_savingdata;
  
  import android.content.ContentValues;
  import android.content.Context;
  import android.database.Cursor;
  import android.database.sqlite.SQLiteDatabase;
  import android.database.sqlite.SQLiteOpenHelper;
  
  /**
   * Created by jarno on 24-1-17.
   */
  
  public class MyDbHandler extends SQLiteOpenHelper {
  
      private static final int DATABASE_VERSION = 1;
      private static final String DATABASE_NAME = "products.db";
      public static final String TABLE_PRODUCTS = "products";
      public static final String COLUMN_ID = "_id";
      public static final String COLUMN_PRODUCTNAME = "productname";
  
      public MyDbHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
          super(context, name, factory, version);
      }
  
      @Override
      public void onCreate(SQLiteDatabase db) {
          String query = "CREATE TABLE " + TABLE_PRODUCTS + "(" +
                  COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT " +
                  COLUMN_PRODUCTNAME + " TEXT "  +
                  ");";
          db.execSQL(query);
      }
  
      @Override
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          db.execSQL("DROP_TABLE_IF_EXISTS" + TABLE_PRODUCTS);
          onCreate(db);
      }
  
      public void addProduct(Products product) {
          ContentValues values = new ContentValues();
          values.put(COLUMN_PRODUCTNAME, product.get_productname());
          SQLiteDatabase db = getWritableDatabase();
          db.insert(TABLE_PRODUCTS, null, values);
          db.close();
      }
  
      public void delProduct(String productName) {
          SQLiteDatabase db = getWritableDatabase();
          db.execSQL("DELETE FROM " + TABLE_PRODUCTS + " WHERE " + COLUMN_PRODUCTNAME + "=\"" + productName + "\";" );
      }
  
      public String databaseToString() {
          String dbString = "";
          SQLiteDatabase db = getWritableDatabase();
          String query = "SELECT * FROM " + TABLE_PRODUCTS + " WHERE 1";
  
          // Cursor point to a location in the results
          Cursor c = db.rawQuery(query, null);
          // Move to the first row in the results
          c.moveToFirst();
  
          while(!c.isAfterLast()) {
              if(c.getString(c.getColumnIndex("productname")) != null) {
                  dbString += c.getString(c.getColumnIndex("productname"));
                  dbString += "\n";
              }
          }
          db.close();
          return dbString;
      }
  }
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>FATAL EXCEPTION: main
                                                   Process: com.example.jarno.a49_savingdata, PID: 4115
                                                   java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.jarno.a49_savingdata/com.example.jarno.a49_savingdata.MainActivity}: android.database.sqlite.SQLiteException: near "productname": syntax error (code 1): , while compiling: CREATE TABLE products(_id INTEGER PRIMARY KEY AUTOINCREMENT productname TEXT ):
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                       at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                       at android.os.Handler.dispatchMessage(Handler.java:102)
                                                       at android.os.Looper.loop(Looper.java:154)
                                                       at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                    Caused by: android.database.sqlite.SQLiteException: near "productname": syntax error (code 1): , while compiling: CREATE TABLE products(_id INTEGER PRIMARY KEY AUTOINCREMENT productname TEXT ):
                                                       at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
                                                       at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)
                                                       at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)
                                                       at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
                                                       at android.database.sqlite.SQLiteProgram.&lt;init&gt;(SQLiteProgram.java:58)
                                                       at android.database.sqlite.SQLiteStatement.&lt;init&gt;(SQLiteStatement.java:31)
                                                       at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1677)
                                                       at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1608)
                                                       at com.example.jarno.a49_savingdata.MyDbHandler.onCreate(MyDbHandler.java:31)
                                                       at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:251)
                                                       at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:163)
                                                       at com.example.jarno.a49_savingdata.MyDbHandler.databaseToString(MyDbHandler.java:55)
                                                       at com.example.jarno.a49_savingdata.MainActivity.printDatabase(MainActivity.java:40)
                                                       at com.example.jarno.a49_savingdata.MainActivity.onCreate(MainActivity.java:23)
                                                       at android.app.Activity.performCreate(Activity.java:6679)
                                                       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                                                       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726) 
                                                       at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                       at android.os.Looper.loop(Looper.java:154) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:6119) 
                                                       at java.lang.reflect.Method.invoke(Native Method) 
                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776) 
  </code></pre>
  
  <p>I think there must be something wrong with this code, but I can't find out what:</p>
  
  <pre><code>"CREATE TABLE " + TABLE_PRODUCTS + "(" +
                  COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT " +
                  COLUMN_PRODUCTNAME + " TEXT "  +
                  ");";
  </code></pre>