Syntax error when using SQLite android "DROP TABLE IF EXISTS"

0

packagecom.example.wesley.bancodedadossqlite;importandroid.database.sqlite.SQLiteDatabase;importandroid.database.sqlite.SQLiteOpenHelper;/***CreatedbyWesleyon17/01/2018.*/publicclassCriaBancoextendsSQLiteOpenHelper{privatestaticfinalStringNOME_BANCO="banco.db";
    private static final String TABELA = "livros";
    private static final String ID = "_id";
    private static final String TITULO = "titulo";
    private static final String AUTOR = "autor";
    private static final String EDITORA = "editora";
    private static final int VERSAO = 1;


    @Override
    public void onCreate(SQLiteDatabase db) {

        String sql = "CREATE TABLE " + TABELA + "("
                + ID + "integer primary key autoincrement,"
                + TITULO + "text,"
                + AUTOR + "text,"
                + EDITORA + "text"
                +")";

        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int i, int i1) {

        db.execSQL("DROP TABLE IF EXISTS" + TABELA);
        onCreate(db);
    }
}
    
asked by anonymous 17.01.2018 / 23:35

1 answer

1

When you put:

db.execSQL("DROP TABLE IF EXISTS" + TABELA)

Your result would be:

DROP TABLE IF EXISTSTABELA

Then to correct, give a "space" after EXISTS , because it is a String :

db.execSQL("DROP TABLE IF EXISTS " + TABELA)

Your result would be:

DROP TABLE IF EXISTS TABELA
    
17.01.2018 / 23:54