2011-01-28 96 views
2

這是我的代碼數據庫SQLite的錯誤時,試圖從數據庫

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 

回答

2

這是錯誤的,因爲也許你正在查詢的格式錯誤。下面的代碼而不是上面


Cursor c = this.db.rawQuery("SELECT * FROM " + TB_SUBCAT + " WHERE cat_id=" + id + " AND typeName=" + typeName,null); 
+0

HI CHIRAG


Cursor c = this.db.rawQuery("SELECT * FROM " + TB_SUBCAT + " WHERE cat_id='" + id + " AND typeName='" + typeName,null); 

使用,您的代碼做工精細100%,得益於你救我的一天:) – geekmyo 2011-01-28 06:31:03