Problem with accentuation when entering data in android Sqlite

Asked

Viewed 745 times

0

I’m trying to give a insert in a table, but it gives syntax error. I believe it is because of the accent, but even searching can not solve.

Log error:

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 noticia (noticia_id, content, title, summary, image, date) VALUES (10228, 'A Chapada Diamantina reserves true natural monuments for those who venture in their ways: some of the highest and beautiful waterfalls of Brazil are here, as a reward, at the end of the trail, for the effort of the travelers. Dazzle yourself with the imposing of the ten largest falls in the region, in images selected by Guidebook.

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);
  • I believe in place of replaceAll("’", "") should be replaceAll("'", "").

1 answer

2


Probably having an injection in your sql, I saw that you used water, is the text not water? because if this is the way the problem is there, this quote is closing the content parameter and is being injected into your sql.

The best way to solve and the most appropriate way would be to use the method itself that the Sqlitedatabase class provides.

Sqlitedatabase has methods of CRUD, it is much more interesting to use them and instead of concatenating in this way that you are making use contentValues, a researched on this.

  • Yes the word is water, it is water because I had already removed that "'".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.