Problem ist, dass Ihre Zeichenfolge ein einzelnes Anführungszeichen hat, die Ihren SQL Query String unterbricht.
Simulieren parametro == test01
- OK
"SELECT titolo, icona, colore, tipo, identificativo, dato_campo FROM table WHERE titolo LIKE '%test01%' OR dato_campo LIKE '%test01%' GROUP BY identificativo";
Simulieren parametro == stringa'
NOK
"SELECT titolo, icona, colore, tipo, identificativo, dato_campo FROM table WHERE titolo LIKE '%stringa'%' OR dato_campo LIKE '%stringa'%' GROUP BY identificativo";
Wie Sie sehen können, Ihre String '%stringa'%'
produziert, die für eine SQL-Abfrage ist ungültig.
Sie sollten das Zeichen '
während Ihrer Abfrage zu etwas wie: %stringa''%'
.
So können Sie etwas wie folgt vor der Erstellung Ihrer Abfrage-Zeichenfolge hinzu:
parametro = parametro.replaceAll("\'","''");
String sql = "SELECT titolo, icona, colore, tipo, identificativo, dato_campo FROM table " +
"WHERE titolo LIKE '%" + parametro + "%' " +
"OR dato_campo LIKE '%" + parametro + "%' GROUP BY identificativo";
Dies ist eine Unterstützung über das Problem, dass Ihr jetzt konfrontiert sind ... Wie Gabe Sechan auf der anderen Antwort erwähnt, roh Abfragen sollten nicht empfohlen werden.
UPDATE
sichere Weg, um Ihre Abfrage auszuführen ist:
String paramentro = "stringa'";
Cursor cursor = db.query("tablename", new String [] {"titolo", "icona", "colore", "tipo", "identificativo", "dato_campo"}, "titolo LIKE ? OR dato_campo LIKE ?", new String[]{"%"+paramentro+"%", "%"+paramentro+"%"}, "identificativo", null, null, null);
bitte Ihr vollständiges Crash-Protokoll hinzufügen – USKMobility