Reputation: 51
I am trying to update the column in the table using update method. I am thrown syntax error like this:
SQLiteException: no such column: DataStructures (code 1): , while compiling: UPDATE tbl_courses SET checked_status=? WHERE course_name=DataStructures
Here is my Database Query:
public static final String TABLE_COURSES = "tbl_courses";
public static final String COLUMN_COURSE_ID = "_id";
public static final String COLUMN_COURSE_NAME = "course_name";
public static final String COLUMN_COURSE_SELECTED = "checked_status";
public static final String COLUMN_COURSE_CODE = "course_code";
public void updateSelectedCourseField(String courseName, String courseSelected) {
ContentValues args = new ContentValues();
args.put(COLUMN_COURSE_SELECTED, courseSelected);
database.update(TABLE_COURSES, args, COLUMN_COURSE_NAME + "=" + courseName,null);
}
I am trying to change checked_status value in tbl_courses where course_name = DataStructures. I am sure its in the database but its throwing me the error. please guide me through this.
Upvotes: 0
Views: 36
Reputation: 83537
A better solution is to avoid string concatenation to build your query. Instead do this:
database.update(TABLE_COURSES, args, COLUMN_COURSE_NAME + "=?", new String[]{courseName});
This will not only take care of the quotes for you, but it will also avoid SQL injection attacks. Always be careful when using user input in a SQL query.
Upvotes: 2