jeudi 31 mars 2016

Android SQLiteException parameter

I'm working very well with the SQLite database, but now I have a problem while using a query. For example, if use a query like this:

SQLiteDatabase db = mHelper.getReadableDatabase();

    String parameter = mypar;
    String sql = SELECT color, name FROM table WHERE name = '" + parameter + "';
    Cursor c = db.rawQuery(sql, null);
   while (c.moveToNext()) {
   String color = c.getString(0);
   String name = c.getString(1);
}
        c.close();
        db.close();

Everything works fine

But if the parameter has an apex

String parameter = mypar';

I get an exception

Caused by: android.database.sqlite.SQLiteException: near "r": syntax error (code 1):

How can I solve this problem? Thank you

Aucun commentaire:

Enregistrer un commentaire