The full error I'm getting is this:
java.lang.RuntimeException: Unable to start activity ComponentInfo{}: android.database.sqlite.SQLiteException: no such column: Cowboy Bebop(code 1): , while compiling: SELECT * FROM anime WHERE title = Cowboy Bebop
Also I get this:
Caused by: android.database.sqlite.SQLiteException: no such column: Cowboy Bebop(code 1): , while compiling: SELECT * FROM anime WHERE title = Cowboy Bebop
Do not use string concatenation to assemble a SQL query this way. You are not properly quoting your value, let alone handle any quotes in the value itself.
Replace queries like:
String query = "SELECT * FROM " + TABLE_SCORES + " WHERE " + KEY_TITLE + " = " + title;
Log.e(DatabaseHelper.class.getName(), query);
Cursor c = db.rawQuery(query,null); //GETTING ERROR HERE
with:
String query = "SELECT * FROM " + TABLE_SCORES + " WHERE " + KEY_TITLE + " = ?";
Log.e(DatabaseHelper.class.getName(), query);
Cursor c = db.rawQuery(query, new String[] { title });
The ?
tells SQLite to bind the supplied argument, handling quoting, escaping of embedded quotes, and so on.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.