I\'ve been getting this error for two days now, and I can\'t find the problem with my code.
here\'s the database code.
SQLHandler.java
When trying to input strings for dummy data, you should call INSERT VALUES ("'text'")
instead of INSERT VALUES ( "text" )
Explanation : Because the sql command will want to see a quote '
around the text and the outer quotes "
is for java to recognise that what you are trying to pass in / concatenate is a string
If room
is a character type (and it is, according to the CREATE_TABLE_2
string where it's defined as TEXT NOT NULL
), you need to replace:
KEY_ROOM + "=" + r
with:
KEY_ROOM + "= '" + r + "'"
The way you have it, you're ending up with the query segment:
where room = kitchen1
and it's complaining that there's no kitchen1
column in that table, rightly so.
By quoting it, you end up with the correct:
where room = 'kitchen1'
This will turn the cursor creation line into:
Cursor c = ourDatabase.query(DATABASE_TABLE2, columns,
KEY_ROOM + "='" + r + "'", null, null, null, null);
// ^^^^^^^^^^^^^^^^^^^^^^^^^
// Changed bit