Syntax Error Near "@domain" Sqlite
I'm having an issue using SQLite. When i'm trying to raw my query here is the error I'm having. 03-05 11:40:54.916: E/AndroidRuntime(6136): Caused by: android.database.sqlite.SQLit
Solution 1:
SQL string literals need to be in ''
single quotes.
However, it's better to use ?
placeholders and bind args for literals:
StringselectQuery="SELECT * FROM " + TABLE_SHOPPING_LIST + " WHERE " + SHOPPING_LIST_OWNER + " = ?";
Cursorcursor= db.rawQuery(selectQuery, newString[] { owner });
Solution 2:
Try Like This
public List<ShoppingListModel> getAllShoppingListByOwner(String owner) {
List<ShoppingListModel> shoppingList = newArrayList<ShoppingListModel>();
StringselectQuery="SELECT * FROM " + TABLE_SHOPPING_LIST + " WHERE " + SHOPPING_LIST_OWNER + " = " + "'"+owner+"'";
SQLiteDatabasedb=this.getWritableDatabase();
Cursorcursor= db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do {
ShoppingListModellist=newShoppingListModel(cursor.getString(cursor.getColumnIndex(SHOPPING_LIST_NAME)),
cursor.getInt(cursor.getColumnIndex(SHOPPING_LIST_ID)),
cursor.getString(cursor.getColumnIndex(SHOPPING_LIST_DATE_CREATION)),
cursor.getString(cursor.getColumnIndex(SHOPPING_LIST_OWNER)));
shoppingList.add(list);
} while (cursor.moveToNext());
}
return shoppingList;
}
Solution 3:
The owner should be surrounded by quotes.
StringselectQuery="SELECT * FROM " + TABLE_SHOPPING_LIST + " WHERE " + SHOPPING_LIST_OWNER + "=\'" + owner + '\'';
Solution 4:
Since your variable owner is of type String , You need to add opening and closing '
single quotes. Use your query following way,
StringselectQuery="SELECT * FROM " + TABLE_SHOPPING_LIST +
" WHERE " + SHOPPING_LIST_OWNER + " ='" + owner + "'";
Post a Comment for "Syntax Error Near "@domain" Sqlite"