Problem with accentuation when entering data in SQLite android

0

I'm trying to give insert in a table, however it gives syntax error. I believe it's because of the accent, but even researching can not solve.

Error log:

  

11-19 00: 34: 52.959: W / AQuery (21157):   reporting: android.database.sqlite.SQLiteException: near "water": syntax   error (code 1):, while compiling: INSERT OR REPLACE into news   (noticia_id, conteudo, title, abstract, image, date) VALUES (10228, 'A   Chapada Diamantina reserves true natural monuments to   those who venture in their paths: some of the highest and   beautiful waterfalls of Brazil are here, as a reward, in the end   of the track, by the effort of the travelers. Be dazzled by the grandeur   the ten largest waterfalls in the region, in images selected by   Guide.

Insert in the code:

String query = "INSERT OR REPLACE into noticia (noticia_id, conteudo, titulo, resumo, imagem, data) VALUES (" + n.getId() + ", '" + n.getPost_content().replaceAll("’", "")
            + "', '" + n.getPost_title() + "', '" + n.getPost_excerpt().replaceAll("’", "") + "', '" + n.getImagem() + "', '" + n.getPost_modified() + "');";

    mDb.execSQL(query);
    
asked by anonymous 19.11.2014 / 04:37

1 answer

2

You are probably having an injection in your sql, I saw that you used water, is there no water in the text? because if this is the way the problem is there, this quote is closing the content parameter and is suffering injection in your sql.

The best way to solve it is to use the same methods that the SQLiteDatabase class provides.

SQLiteDatabase has CRUD methods, it is much more interesting to use them and instead of concatenating in this way that you are doing use contentValues, from a researched one.

    
19.11.2014 / 05:42