-2

I am somewhere wrong with syntax.

Crash comes when ever i call clearAll() method here is my method.

    /**
     * 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);
    }

Query:

DROP TABLE IF EXISTS create table 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 )

Crash report:

04-02 16:11:50.943 23043-23043/com.app.hupo D/AndroidRuntime: Shutting down VM 04-02 16:11:50.944 23043-23043/com.app.hupo E/AndroidRuntime: FATAL EXCEPTION: main Process: com.app.hupo, PID: 23043 android.database.sqlite.SQLiteException: near "create": syntax error (code 1): , while compiling: DROP TABLE IF EXISTS create table 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 ) 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.(SQLiteProgram.java:58) at android.database.sqlite.SQLiteStatement.(SQLiteStatement.java:31) at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1675) at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1606) at com.app.hupo.database.DataBaseHelper.clearAll(DataBaseHelper.java:1048) at

8
  • Update question with CREATE TABLE QUERY Commented Apr 2, 2018 at 10:55
  • You can uninstall and re-install app hope it will work or if this still occurs try to update DATABASE_VERSION Commented Apr 2, 2018 at 10:57
  • @Lucifer it is already available in crash report Commented Apr 2, 2018 at 10:59
  • 1
    Where did you get that syntax:DROP TABLE IF EXISTS CREATE TABLE ...?! Commented Apr 2, 2018 at 11:07
  • 1
    Could you show the SqlConstant class? Commented Apr 2, 2018 at 11:11

1 Answer 1

2

android.database.sqlite.SQLiteException: near "create": syntax error (code 1): , while compiling: DROP TABLE IF EXISTS create table user_personal_detail..

here, the table name is missing .

You need to remove SqlConstant.DROP_TABLE+

Or use,

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

Your command should be like,

DROP TABLE IF EXISTS user_personal_detail ; create table user_personal_detail...

Do it for all the tables.

Sign up to request clarification or add additional context in comments.

4 Comments

Then you need to use drop table if exists tablename. In your code table name is missing
Are you getting any exception after adding table name?
Same exception is coming
Please post the exception which you got now. And also do Clean your project,do invalidate caches then debug app

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.