1
這裏我試圖從SQLite表中獲取所有數據。但每次它只返回最後兩行(我的表只包含兩行)。僅返回SQLite中的最後一個值Select Statement
e.g
---------------------+
| Id| name | mobile |
|--------------------|
|1 | abc | 123456 |
|--------------------|
|2 | xyz | 789654 |
+--------------------+
我的代碼返回此:
01-11 00:14:59.291: D/Result:(27629): TID 12274, Name: Tablets , Image: [[email protected]
01-11 00:14:59.291: D/Result:(27629): TID 12274, Name: Tablets , Image: [[email protected]
在這裏,我貼我的查詢代碼:
public List<ProductCategoryDatabaseRetrieve> getProductCategoryData() {
List<ProductCategoryDatabaseRetrieve> productCategoryDatabaseRetrieve = new ArrayList<ProductCategoryDatabaseRetrieve>();
ProductCategoryDatabaseRetrieve prodCatDB = new ProductCategoryDatabaseRetrieve();
SQLiteDatabase sqliteDB = dbHandler.getWritableDatabase();
String[] columns = { DatabaseHandler._TID,
DatabaseHandler.TID,
DatabaseHandler.PRODUCT_CATEGORY_NAME,
DatabaseHandler.PRODUCT_CATEGORY_IMAGE };
Cursor cursor = sqliteDB.query(DatabaseHandler.PRODUCT_CATEGORY_TABLE,
columns, null, null, null, null, null);
if (cursor.getCount() > 0 && cursor !=null) {
while (cursor.moveToNext()) {
prodCatDB.set_tid(cursor.getInt(cursor.getColumnIndex(DatabaseHandler._TID)));
prodCatDB.setTid(String.valueOf(cursor.getInt(cursor
.getColumnIndex(DatabaseHandler.TID))));
prodCatDB.setProductCategoryName(cursor.getString(cursor
.getColumnIndex(DatabaseHandler.PRODUCT_CATEGORY_NAME)));
prodCatDB.setProductCategoryImage(cursor.getBlob(cursor
.getColumnIndex(DatabaseHandler.PRODUCT_CATEGORY_IMAGE)));
productCategoryDatabaseRetrieve.add(prodCatDB);
}
}
dbHandler.close();
return productCategoryDatabaseRetrieve;
}
感謝很多關於考慮。
謝謝Yasmani :) – rup35h
沒問題:-)。 – AxiomaticNexus