Android: Database Handler Sqliteexception
Hello all i have this method in the database handler class and what this class do is to return the ID of the product from the product table. However, i am receiving this sqliteexce
Solution 1:
Since product name is in String Format use '
in query, like below,
StringselectQuery="SELECT productid FROM " + TABLE_PRODUCT
+ " WHERE " + KEY_PRODUCTNAME +" ='" + productName +"'";
Solution 2:
I'd rather write it so:
StringselectQuery="SELECT productid FROM " + TABLE_PRODUCT+ " WHERE " + KEY_PRODUCTNAME + " = ?";
SQLiteDatabasedb=this.getReadableDatabase();
Cursorcursor= db.rawQuery(selectQuery, newString[]{productName});
Solution 3:
Any string value in database transactions should be accessed in '
single quote only.
Just write your product value in single quote '
as below:
" = '" + productName +"'";
Query:
"SELECT productid FROM " + TABLE_PRODUCT+ " WHERE " +KEY_PRODUCTNAME +" = '" + productName +"'";
Solution 4:
it just a simple mistake. you forgot to add single qoute like below:
StringselectQuery="SELECT productid FROM " + TABLE_PRODUCT+ " WHERE " +KEY_PRODUCTNAME +" = '" + productName +"'";
Post a Comment for "Android: Database Handler Sqliteexception"