语法错误sqlite表未创建

时间:2014-10-05 17:42:58

标签: android database sqlite

这是我的代码我在logcat中遇到了这个错误。

  

10-05 17:40:09.650:E / Database(1595):在准备'CREATE TABLE mytable(_id INTEGER PRIMARY,名称文本不为空,设计文本)时,在0x8b2d440上失败1(接近“,”:语法错误) not null,salary text not null,join text not null,dpay text not null)'。

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);

            }
    }

1 个答案:

答案 0 :(得分:0)

PRIMARY替换为PRIMARY KEY

将列join更改为其他名称 - join是保留的SQL关键字。