删除表

时间:2018-04-02 10:55:12

标签: java android database sqlite

我的语法错误。

当我在这里调用clearAll()方法是我的方法时崩溃来了。

    /**
     * Method to clear all db
     */
    public void clearAll() {
        if(sqLiteDatabase==null){
            sqLiteDatabase=this.getWritableDatabase();
        }else {
            if(!sqLiteDatabase.isOpen()){
                sqLiteDatabase=this.getWritableDatabase();
            }
        }
        sqLiteDatabase.execSQL(SqlConstant.DROP_TABLE+ SqlConstant.CREATE_USER_PERSONAL_DETAILS);
        sqLiteDatabase.execSQL(SqlConstant.DROP_TABLE+ SqlConstant.CREATE_POSITIONS);
        sqLiteDatabase.execSQL(SqlConstant.DROP_TABLE+ SqlConstant.CREATE_TABLE_INDUSTRY);
        sqLiteDatabase.execSQL(SqlConstant.DROP_TABLE+ SqlConstant.CREATE_TABLE_INTERESTS);
        sqLiteDatabase.execSQL(SqlConstant.DROP_TABLE+ SqlConstant.CREATE_TABLE_JOB_LOCATION);
        sqLiteDatabase.execSQL(SqlConstant.DROP_TABLE+ SqlConstant.CREATE_TABLE_JOB_CITY);
        sqLiteDatabase.execSQL(SqlConstant.DROP_TABLE+ SqlConstant.CREATE_TABLE_KNOWN_LANGUAGE);
        sqLiteDatabase.execSQL(SqlConstant.DROP_TABLE+ SqlConstant.CREATE_TABLE_ORGANIZATION_DETAILS);
        sqLiteDatabase.execSQL(SqlConstant.DROP_TABLE+ SqlConstant.CREATE_TABLE_QUALIFICATIONS);
        sqLiteDatabase.execSQL(SqlConstant.DROP_TABLE+ SqlConstant.CREATE_TABLE_CURRENT_LOCATION);
    }

查询:

  

DROP TABLE IF EXISTS创建表user_personal_detail(first_name varchar2,middle_name varchar2,last_name varchar2,   user_name varchar2,email_id varchar2,alternative_email_id varchar2   ,phone_number varchar2,mobile_code varchar2,date_of_birth   varchar2,性别varchar2,marrital_status varchar2,   education_level varchar2,profile_image varchar2,hupo_score   varchar2,hupo_loyalty_point varchar2,signup_date varchar2,   totalWorkExperience varchar2)

崩溃报告:

  

04-02 16:11:50.943 23043-23043 / com.app.hupo D / AndroidRuntime:关闭VM       04-02 16:11:50.944 23043-23043 / com.app.hupo E / AndroidRuntime:FATAL EXCEPTION:main                                                                     处理:com.app.hupo,PID:23043                                                                     android.database.sqlite.SQLiteException:near" create&#34 ;:语法错误   (代码1):,编译时:DROP TABLE IF EXISTS创建表   user_personal_detail(first_name varchar2,middle_name varchar2,   last_name varchar2,user_name varchar2,email_id varchar2,   alternative_email_id varchar2,phone_number varchar2,mobile_code   varchar2,date_of_birth varchar2,gender varchar2,marrital_status   varchar2,education_level varchar2,profile_image varchar2,   hupo_score varchar2,hupo_loyalty_point varchar2,signup_date   varchar2,totalWorkExperience varchar2)                                                                         在   android.database.sqlite.SQLiteConnection.nativePrepareStatement(母语   方法)                                                                         在   android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:889)                                                                         在   android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:500)                                                                         在   android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)                                                                         在android.database.sqlite.SQLiteProgram。(SQLiteProgram.java:58)                                                                         在   android.database.sqlite.SQLiteStatement。(SQLiteStatement.java:31)                                                                         在   android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1675)                                                                         在   android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1606)                                                                         在   com.app.hupo.database.DataBaseHelper.clearAll(DataBaseHelper.java:1048)                                                                         在

1 个答案:

答案 0 :(得分:2)

  

android.database.sqlite.SQLiteException:near“create”:语法错误   (代码1):,编译时:DROP TABLE IF EXISTS创建表   user_personal_detail ..

此处,表名称缺失

您需要移除 SqlConstant.DROP_TABLE+

或者使用,

 SqlConstant.DROP_TABLE+ "tablename ;"+SqlConstant.CREATE_USER_PERSONAL_DETAILS)

你的命令应该是,

  

DROP TABLE IF EXISTS user_personal_detail;创建表   user_personal_detail ...

为所有表格做。