1

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

That worked! Thanks a lot! I'm also running into 1 more problem if you don't mind helping.
@user2923535: "I'm also running into 1 more problem" -- I suggest that you ask a fresh Stack Overflow question, where you provide your (revised) code and an explanation of your problem.
Okay will do! Thanks again!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.