这是我的数据库代码
public ArrayList<SubCatInfo> getSubCatByCatIdAndtypeName(int id,
String typeName) {
ArrayList<SubCatInfo> list = new ArrayList<SubCatInfo>();
Cursor c = this.db.rawQuery("SELECT * FROM " + TB_SUBCAT
+ " WHERE cat_id='" + id + " AND typeName='" + typeName,null);
logcat显示,
01-28 12:28:46.693: ERROR/AndroidRuntime(260): Caused by: android.database.sqlite.SQLiteException: near "1": syntax error: , while compiling: SELECT * FROM tbl_subcategories WHERE cat_id='11 AND typeName='1
答案 0 :(得分:2)
这是错误,因为您可能错误地格式化查询。
Cursor c = this.db.rawQuery("SELECT * FROM " + TB_SUBCAT + " WHERE cat_id='" + id + " AND typeName='" + typeName,null);
使用下面的代码代替上面的
Cursor c = this.db.rawQuery("SELECT * FROM " + TB_SUBCAT + " WHERE cat_id=" + id + " AND typeName=" + typeName,null);