android.database.sqlite.SQLiteException: near ")": syntax error (code 1):
android.database.sqlite.SQLiteException: near ")": syntax error (code 1):
public String getProductName(double id) {
database = DBHelper.getReadableDatabase(); // open database to perform some operation
Cursor c = database.rawQuery("SELECT " + COL_PRODUCT_NAME + " FROM "
+ TABLE_PRODUCT + " WHERE " + COL_CATEGORY + "= " + id +" ", null);
if(c.moveToFirst())
{
String strCatName = c.getString(c.getColumnIndex(COL_PRODUCT_NAME));
c.close();
database.close();
return strCatName;
}
else
{
return "";
}
}
public String getProductName(double id) {
database = DBHelper.getReadableDatabase(); // open database to perform some operation
Cursor c = database.rawQuery("SELECT " + COL_PRODUCT_NAME + " FROM "
+ TABLE_PRODUCT + " WHERE " + COL_CATEGORY + "= " + id +" ", null);
if(c.moveToFirst())
{
String strCatName = c.getString(c.getColumnIndex(COL_PRODUCT_NAME));
c.close();
database.close();
return strCatName;
}
else
{
return "";
}
}
Here's the problem :
view plaincopy to clipboardprint?
Note: Text content in the code blocks is automatically word-wrapped
07-14 16:51:15.683: E/AndroidRuntime(1497): Caused by: android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: SELECT COUNT(*) FROM table_product WHERE category = '3')
That's odd - somehow an extra ')' seems to get appended to the query. But it's anyway odd since the query has single quotes around the '3' - which your code doesn't add, assuming that what you posted is precisely what gets run.