android.database.sqlite.SQLiteException:near“;”:语法错误(代码1)

时间:2015-09-25 13:50:53

标签: java android sqlite

它表示createTable字符串出错了,

我的数据库类....

class DataBase extends SQLiteOpenHelper{
            private final static String createTable="CREATE TABLE "+Keys.Database.TableName+
                    "("+Keys.Database._Id+" INTEGER PRIMARY KEY AUTOINCREMENT, "
                    +Keys.Database.Date+" TEXT(50), "
                    +Keys.Database.Type+" TEXT(50), "
                    +Keys.Database.City+" TEXT(100);";
            private final static String dropTable = "DROP TABLE IF EXISTS"+Keys.Database.TableName+";";

            private DataBase(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
                super(context, name, factory, version);
            }

            private DataBase(Context context, String name, SQLiteDatabase.CursorFactory factory, int version, DatabaseErrorHandler errorHandler) {
                super(context, name, factory, version, errorHandler);
            }


            @Override
            public void onCreate(SQLiteDatabase db) {

                    db.execSQL(createTable);

            }

            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                db.execSQL(dropTable);
                onCreate(db);
            }
        }

以下是我正在尝试创建表格的一些代码

public void writeHistory(String date, String type, String city){
        database = new DataBase(context,Keys.Database.DataBaseName,null,Keys.Database.Version);
        SQLiteDatabase sqLiteDatabase = database.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put(Keys.Database.Date,date);
        contentValues.put(Keys.Database.Type,type);
        contentValues.put(Keys.Database.City, city);
        long i=sqLiteDatabase.insert(Keys.Database.TableName,null,contentValues);
        if (i<0){
            Toast.makeText(MyApplication.getMyAppContext(),"History insertion FAILED",Toast.LENGTH_LONG).show();
        }
        else {
            Toast.makeText(MyApplication.getMyAppContext(),"History insertion SUCCESSFUL",Toast.LENGTH_LONG).show();
        }
    }

创建表时我遇到了这个错误,请帮忙...... 提前谢谢..

1 个答案:

答案 0 :(得分:1)

oops发现它......:p

private final static String createTable="CREATE TABLE "+Keys.Database.TableName+
                    "("+Keys.Database._Id+" INTEGER PRIMARY KEY AUTOINCREMENT, "
                    +Keys.Database.Date+" TEXT(50), "
                    +Keys.Database.Type+" TEXT(50), "
                    +Keys.Database.City+" TEXT(100));";

这只是一个愚蠢的支架..