1

我使用 SQLiteQueryBuilder 使用以下代码从我的数据库中查询信息

SQLiteQueryBuilder builder = new SQLiteQueryBuilder();
builder.setTables("customers");
Cursor cursor = builder.query(database, null, null, null, null, null, null);

但我没有收到光标中的任何元素

我确信数据库中有数据

我的代码有什么问题?

4

1 回答 1

0

It's hard to determine from what you've placed, but the most likely is the previous query you posted.

final static String CUSTOMERS_TABLE = "customers";
database.rawQuery("select * from CUSTOMERS_TABLE", null);

If this is what your code actually is, you need to concatenate your query with the constant, otherwise you will get no results because CUSTOMERS_TABLE doesn't exist, but customers does.

Something like this

final static String CUSTOMERS_TABLE = "customers";
database.rawQuery("select * from " + CUSTOMERS_TABLE, null);

Be careful here

  • The first example will create the query "select * from CUSTOMERS_TABLE"
  • The second example will create the query "select * from customers"

If you're still getting no results, you may actually have no data. Make sure to check that as well.

于 2013-02-18T21:15:51.367 回答