2014-10-05 106 views
0

這是我的代碼我得到了這個錯誤logcat。語法錯誤sqlite表未創建

10-05 17:40:09.650:上0x8b2d440準備「CREATE TABLE MYTABLE(_id INTEGER PRIMARY時,名稱的文本不爲空E /數據庫(1595):1失敗(語法錯誤附近 「」) ,設計文本不爲空,工資文本不爲空,連接文本不爲空,付款文本不爲空)'。

package example.servant; 

    import android.content.Context; 
    import android.database.sqlite.SQLiteDatabase; 
    import android.database.sqlite.SQLiteOpenHelper; 
    import android.util.Log; 

    public class datahandler extends SQLiteOpenHelper { 

     public static final String KEY_ID="_id"; 
     public static final String KEY_NAME="name"; 
     public static final String KEY_DESIG="desig"; 
     public static final String KEY_SALARY="salary"; 
     public static final String KEY_DPAY="dpay"; 
     public static final String KEY_JOIN="join"; 

     public static final String DATABASE_NAME="servantrecord.sqlite"; 
     public static final String TABLE_NAME="mytable"; 
     public static final String TAG="datahandler"; 
     public static final int DATABASE_VERSION=1; 

     public static final String DATABASE_CREATE=("CREATE TABLE " + TABLE_NAME + " (" + KEY_ID 
       + " INTEGER PRIMARY, " + KEY_NAME + " text not null, " 
       + KEY_DESIG + " text not null, " + KEY_SALARY + " text not null, " 
       + KEY_JOIN + " text not null, " + KEY_DPAY + " text not null)"); 


     public datahandler(Context context){ 

      super(context, DATABASE_NAME, null, DATABASE_VERSION); 

      Log.d("datahandler", "Database created"); 

     } 

      @Override 
      public void onCreate(SQLiteDatabase db) { 

        db.execSQL(DATABASE_CREATE); 
        Log.d("datahandler", "table created"); 

      } 

      @Override 
      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 

       db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); 
       onCreate(db); 

      } 
    } 

回答

0

更換PRIMARYPRIMARY KEY

將列join更改爲其他名稱 - join是保留的SQL關鍵字。

+0

是的,它的作品「加入」是主要問題,謝謝你謝謝ALOT :) – 2014-10-05 18:00:38