public int getCount(String mac) { int count = 0; String sql = String.format("Select count(*) from %s where %s='%s'", TABLE_NAME, KEY_ID, mac); Cursor cursor = db.rawQuery(sql, null); try { cursor.moveToFirst(); count = cursor.getInt(0); cursor.close(); } catch (Exception e) { } return count; }
不要直接去取count這攔位,會GG。
參考資料:
http://stackoverflow.com/questions/5202269/sqlite-query-in-android-to-count-rows
沒有留言:
張貼留言